我正在全局设置我所有 UISegmentedControl 的外观。但是我注意到,当我这样做时,它会破坏禁用状态。
这是我必须更改 titleTextAttributes 的代码
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:12], UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor colorWithRed:0x49/255.0 green:0x49/255.0 blue:0x49/255.0 alpha:1], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
nil];
[[UISegmentedControl appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
现在这很好用,并且所有分段控制器都已更新。
但是我使用 setEnabled:forSegmentAtIndex: 禁用的项目不再被禁用并且可以点击。为什么会这样?我怎样才能让他们再次被禁用。我也尝试将其应用于禁用状态,但它不起作用。
[[UISegmentedControl appearance] setTitleTextAttributes:attributes forState:UIControlStateDisabled];