如何更改段分隔符颜色?

How to Change Segment Separator Color?

在我的项目中,我使用的是段控制器..它们在我的段控制器中有四个段..我的问题是我想要这种背景颜色和字体颜色以及状态 selected 颜色和分隔符颜色[白色当 select 段]

喜欢这张图片

但是我的屏幕是

我的代码是

- (void)viewDidLoad {
[self changeColor];

}
- (void)changeColor{

    [[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:83.0f/255.0f green:198.0f/255.0f blue:255.0f/255.0f alpha:1.0]} forState:UIControlStateSelected];

    [[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:197.0f/255.0f green:197.0f/255.0f blue:197.0f/255.0f alpha:1.0]} forState:UIControlStateNormal];

    [mailboxsegment setTintColor:[UIColor colorWithRed:202.0f/255.0f green:202.0f/255.0f blue:202.0f/255.0f alpha:1.0]];
     UIFont *font = [UIFont boldSystemFontOfSize:09.0f];
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
                                                      forKey:NSFontAttributeName];
   [mailboxsegment setTitleTextAttributes:attributes forState:UIControlStateNormal];


}

我的代码我会尝试改变背景颜色和字体大小

您可以创建自定义 segmented control。但是创建自定义 segmented control 有点复杂,因为您必须为 selecteddeselected 状态提供 images,为 separator 等提供 1px image .

相反,我建议您使用四种不同的 buttons 并将逻辑应用到 select 一次仅一个 button

要获得 separator 颜色的效果,请将这四个 buttons 放在 stack view 或普通 UIView 中,并将该容器视图的背景颜色设置为该颜色您要为 separator.

设置的
please try this one 

- (void)segmentAction:(UISegmentedControl *)segment 
{ 
    UIColor *selectedColor = [UIColor whiteColor]; 
    UIColor *deselectedColor = [UIColor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 alpha:1.0]; 

    for (UIControl *subview in [segment subviews]) 
    { 
        if ([subview isSelected]) 
        [subview setTintColor:selectedColor]; 
        else 
        [subview setTintColor:deselectedColor]; 
    } 
}