使用以下代码,我尝试更改 UISegmentedControl 的外观,但只有文本颜色会随着突出显示或选定的选项卡而改变。字体和粗细取自非活动属性,因此分段控件的所有部分都在标题标签上显示 Futura-Medium,无论是突出显示、选中还是正常。为什么是这样?
NSDictionary *attributesActive = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"AmericanTypewriter-Bold" size:22.f], UITextAttributeFont,
[UIColor redColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
nil];
NSDictionary *attributesInactive = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Futura-Medium" size:16.f], UITextAttributeFont,
[UIColor greenColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
nil];
[segmentedControl setTitleTextAttributes:attributesActive forState:UIControlStateHighlighted];
[segmentedControl setTitleTextAttributes:attributesActive forState:UIControlStateSelected];
[segmentedControl setTitleTextAttributes:attributesInactive forState:UIControlStateNormal];