我的iPad应用程序中有一个UISegmentedControl,我已经使用iOS5中的新方法对其进行了自定义,如下所示:
[[UISegmentedControl appearance] setBackgroundImage:segmentUnselected forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:segmentSelected forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segmentUnselectedUnselected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segUnselectedSelected forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
NSDictionary *textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], UITextAttributeFont,
[UIColor colorWithRed:0.3 green:0.34 blue:0.42 alpha:1], UITextAttributeTextColor,
[UIColor whiteColor], UITextAttributeTextShadowColor,
CGSizeMake(0, 1), UITextAttributeTextShadowOffset, nil];
[[UISegmentedControl appearance] setTitleTextAttributes:textAttributes forState:UIControlStateNormal];它看起来很好,工作也很好,但是调用setEnabled:NO对任何段都没有影响-段仍然会响应触摸事件。有人知道我需要做些什么来禁用某些段吗?
发布于 2013-03-05 11:54:15
不确定这对任何人来说是否仍然是一个问题(因为它在iOS 6中已经修复,但以下是我的解决方法(借用另一个问题):
在您的viewDidLoad中,尝试:
dispatch_async(dispatch_get_main_queue(),^{
[self.segmentedControl setEnabled:NO forSegmentAtIndex:2];
});当视图加载时,外观代理的存在似乎会重置UISegmentedControl的其他属性。在主线程上调度它将重新启用/重新禁用。这也适用于选择缺省段。
https://stackoverflow.com/questions/10806510
复制相似问题