UISegmentedControl仅在选择片段时显示高亮颜色

时间:2015-11-25 21:20:38

标签: ios

我在我的视图中添加了一个UISegmentedControl:

 UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:@[@"Red",@"Green",@"Blue"]];
 segControl.frame = CGRectMake(35, 200, 250, 50);
 [segControl addTarget:self action:@selector(MySegmentControlAction:) forControlEvents: UIControlEventValueChanged];
...

我面临的问题如下图所示: enter image description here

我使用默认颜色&它的风格。选择一个分段按钮后,按钮的颜色保持蓝色,即使我选择了另一个分段。如何使它只有在选择了段时,它才会显示高亮默认颜色,否则会更改回未选择的样式?

以下是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;
}

1 个答案:

答案 0 :(得分:0)

segmentedControl.tintColor = [UIColor yourColor];