//分段控件
UISegmentedControl *segmentControl = [[UISegmentedControl alloc]initWithItems:@[@"white",@"red",@"blue",@"green"]];
segmentControl.bounds = CGRectMake(0, 0, 200, 30);
segmentControl.center = CGPointMake(self.view.frame.size.width/2, 500);
[segmentControl setSelectedSegmentIndex:0];
//
[segmentControl setTintColor:[UIColor grayColor]];
[segmentControl addTarget:self action:@selector(processControl:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentControl];
[segmentControl release];
- (void)processControl:(UIView *)sender{
if ([sender isKindOfClass:[UISwitch class]]) {
UISwitch *swithControl = (UISwitch *)sender;
[self.view setBackgroundColor:swithControl.isOn ? [UIColor colorWithRed:1 green:0.2 blue:0.3 alpha:100] :[UIColor whiteColor]];
UIActivityIndicatorView *indicatorView = (UIActivityIndicatorView *)[self.view viewWithTag:11];
if (swithControl.isOn) {
[indicatorView stopAnimating];
}else{
[indicatorView startAnimating];
}
}
else if([sender isKindOfClass:[UISlider class]]){
UISlider *slider = (UISlider *)sender;
NSLog(@"slider value is '%.1f'.",slider.value);
// [self.view setAlpha:slider.value];
UIProgressView *progressView = (UIProgressView *)[self.view viewWithTag:10];
[progressView setProgress:slider.value / slider.maximumValue animated:YES];
}
else if([sender isKindOfClass:[UISegmentedControl class]]){
UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
NSArray *colorList = @[[UIColor whiteColor],[UIColor redColor],[UIColor blueColor],[UIColor greenColor]];
[self.view setBackgroundColor:colorList[segmentedControl.selectedSegmentIndex]];
}
}