//以选择开关的实现方法为例
-(void)segmentedAction:(UISegmentedControl *)sender
{
//通过 sender.selectedSegmentIndex 判断选中的哪一个 segmented
if (sender.selectedSegmentIndex == 0) {
self.backgroundColor = [UIColor redColor];
}else if (sender.selectedSegmentIndex == 1){
self.backgroundColor = [UIColor lightGrayColor];
}else if(sender.selectedSegmentIndex == 2){
self.backgroundColor = [UIColor blackColor];
}
switch (sender.selectedSegmentIndex) {
case 0:
self.backgroundColor = [UIColor redColor];
break;
case 1:
self.backgroundColor = [UIColor lightGrayColor];
break;
case 2:
self.backgroundColor = [UIColor blackColor];
break;
default:
break;
}
-(void)segmentedAction:(UISegmentedControl *)sender
{
//通过 sender.selectedSegmentIndex 判断选中的哪一个 segmented
if (sender.selectedSegmentIndex == 0) {
self.backgroundColor = [UIColor redColor];
}else if (sender.selectedSegmentIndex == 1){
self.backgroundColor = [UIColor lightGrayColor];
}else if(sender.selectedSegmentIndex == 2){
self.backgroundColor = [UIColor blackColor];
}
switch (sender.selectedSegmentIndex) {
case 0:
self.backgroundColor = [UIColor redColor];
break;
case 1:
self.backgroundColor = [UIColor lightGrayColor];
break;
case 2:
self.backgroundColor = [UIColor blackColor];
break;
default:
break;
}
}
//1,------------ 当用if进行判断时,不管你点击的sender.selectedSegmentIndex是0,1,2,程序都会从sender.selectedSegmentIndex == 0,==1,==2,一个一个进行判断