我在我的视图中添加了一个UISegmentedControl:
UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:@[@"Red",@"Green",@"Blue"]];
segControl.frame = CGRectMake(35, 200, 250, 50);
[segControl addTarget:self action:@selector(MySegmentControlAction:) forControlEvents: UIControlEventValueChanged];
...
我使用默认颜色&它的风格。选择一个分段按钮后,按钮的颜色保持蓝色,即使我选择了另一个分段。如何使它只有在选择了段时,它才会显示高亮默认颜色,否则会更改回未选择的样式?
以下是MySegmentControlAction
功能:
- (void)MySegmentControlAction:(UISegmentedControl *) segment {
UIColor *color;
switch(segment.selectedSegmentIndex) {
case 0:
color = [UIColor redColor];
break;
case 1:
color = [UIColor greenColor];
break;
case 2:
color = [UIColor blueColor];
break;
}
self.circleColor = color;
}
答案 0 :(得分:0)
segmentedControl.tintColor = [UIColor yourColor];