是否有人设法给UISearchBar的作用域部分着色,它有一个tintColor属性,但设置它不会影响附加的作用域UISegmentedControl。我有一个把手在酒吧给它染色,但似乎不起作用,例如:
for (id subview in searchBar.subviews){
if([subview isMemberOfClass:[UISegmentedControl class]]){
UISegmentedControl *scopeBar=(UISegmentedControl *) subview;
scopeBar.tintColor=UIColorFromRGB(0x990066);
}
}干杯,尼尔
发布于 2009-11-19 11:41:37
这很有趣,原来范围栏是一个自定义的分段控件。
来自文档:仅当分段控件的样式为UISegmentedControlStyleBar时,UISegmentedControl才使用此属性。
现在,范围栏分段控件看起来像UISegmentedControlStyleBar,但它不是,它是一些未记录的样式:
NSLog(@"scope bar style is %d", scopeBar.segmentedControlStyle);
> scope bar style is 7你可以试试这个,它确实设置了色调,但它看起来像是臀部:
[scopeBar setSegmentedControlStyle:UISegmentedControlStyleBar];
[scopeBar setTintColor: UIColorFromRGB(0x990066)];
> scope bar style is 2在内部,有一些实例变量会影响这一点:_segementedControlFlags.style和_barStyle,但您无法破解这些变量,除非您绕过已批准的API。
最好的做法是向苹果提出这个问题,并希望他们在未来的版本中包含一个修复。
发布于 2013-09-18 09:56:31
上面的方法对我不起作用,我最终使用了iOS外观方法。
[[UISegmentedControl appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor:[UIColor whiteColor]];发布于 2010-07-20 08:48:26
这里有一些复制粘贴友好的代码,用于其他人正在讨论的内容。
scopeBar.segmentedControlStyle = UISegmentedControlStyleBar; //required for color change
for (id subview in self.searchDisplayController.searchBar.subviews )
{
if([subview isMemberOfClass:[UISegmentedControl class]])
{
UISegmentedControl *scopeBar=(UISegmentedControl *) subview;
scopeBar.tintColor = [UIColor blackColor];
}
}如果你的按钮周围有一个类似白色方框的区域,你可以通过界面生成器来改变它的颜色。
我不会像其他人那样说它看起来“像个笨蛋”,但它也不是真正理想的。
https://stackoverflow.com/questions/1661061
复制相似问题