0

我正在全局设置我所有 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];
4

1 回答 1

0

看来为 UISegmentedControl 设置全局外观并不是最好的方法,因为它不尊重 UIControlStateDisabled。

我以为我必须使用 UIControlStateDisabled ,因为没有任何效果,但似乎直接设置背景是有效的。所以我刚刚创建了一个初始化背景的 UISegmentedControlExtended 类,现在 setEnabled 函数可以正常工作。

于 2012-11-28T16:14:19.610 回答