UISegmentedControl文本颜色问题

时间:2014-05-08 18:08:22

标签: ios uisegmentedcontrol

我使用它来更改分段控件文本的文本颜色,但其颜色在UIControlStateNormal中没有更改。我必须为这两个州保持相同的颜色。

NSDictionary *highlightedAttributes = [NSDictionary 
    dictionaryWithObject:[UIColor blueColor] forKey:UITextAttributeTextColor];
[self.segmentController
    setTitleTextAttributes:highlightedAttributes forState:UIControlStateSelected];

2 个答案:

答案 0 :(得分:0)

您还必须为正常状态(UIControlStateNormal)明确设置任何属性。

答案 1 :(得分:0)

试试这个:

NSDictionary *textAttributes = @{NSFontAttributeName: [UIFont systemFontOfSize:13],
                                 UITextAttributeTextColor: UIColorFromRGB(0x93938D),
                                 UITextAttributeTextShadowColor: [UIColor clearColor]
                                 };
[self.segmentController setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
[self.segmentController setTitleTextAttributes:textAttributes forState:UIControlStateSelected];