Ios 如何更改段分隔符颜色?

Ios 如何更改段分隔符颜色?,ios,objective-c,uisegmentedcontrol,Ios,Objective C,Uisegmentedcontrol,在我的项目中,我使用段控制器。。他们在我的段控制器中有四个段..我的问题是我想要这个背景颜色和字体颜色,并说明选择的颜色和分隔符颜色[选择段时为白色] 喜欢这个图像吗 但是我的屏幕是 我的代码是 - (void)viewDidLoad { [self changeColor]; } - (void)changeColor{ [[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttr

在我的项目中,我使用段控制器。。他们在我的段控制器中有四个段..我的问题是我想要这个背景颜色和字体颜色,并说明选择的颜色和分隔符颜色[选择段时为白色]

喜欢这个图像吗

但是我的屏幕是

我的代码是

- (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];


}

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

您可以创建自定义的
分段控件
。但是创建自定义的
分段控件
并不复杂,因为您必须为
选中的
取消选中的
状态提供
图像
,为
分隔符提供1px
图像

与此相反,我建议您使用四个不同的
按钮
,并应用逻辑一次只选择一个
按钮


要获得
分隔符
颜色的效果,请将这四个
按钮
放置在
堆栈视图
或普通
ui视图
中,并将该容器视图的背景色设置为要为
分隔符

UIColor*selectedColor=[UIColor COLOR WITHRED:98/255.0绿色:156/255.0蓝色:247/255.0 alpha:1.0];UIColor*取消选择颜色=[UIColor COLOR WITHRED:54/255.0绿色:52/255.0蓝色:48/255.0 alpha:1.0];用于(UIControl*子视图在[SegmentRound子视图]{if([subview isSelected])[subview isSelected])[subview setTintColor:selectedColor];else[子视图setTintColor:DesceledColor];}好的,如果有任何问题,我将尝试@Birendraok,然后告诉我Yeah Deafolt select first only change white color..如果我单击了第二段或第三段,则第四段only change segment color in black..not white您将此代码放在哪里?
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]; 
    } 
}