UISearchBAR scopeBar tintColor

Nei*_*rds 15 uisearchbar

有没有人设法为UISearchBar的scopebar部分着色,它有一个tintColor属性,但设置它不会影响附加的scopebar UISegmentedControl.我在酒吧有一个把它染色的手柄,但似乎没有工作,即:

for (id subview in searchBar.subviews){
  if([subview isMemberOfClass:[UISegmentedControl class]]){
     UISegmentedControl *scopeBar=(UISegmentedControl *) subview;
    scopeBar.tintColor=UIColorFromRGB(0x990066);
 }
}
Run Code Online (Sandbox Code Playgroud)

干杯,尼尔

rai*_*ive 9

以上方法对我不起作用,最后我使用了iOS外观方法.

[[UISegmentedControl appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)


小智 7

这很有趣,结果范围栏是一个有点定制的分段控件.

从文档:UISegmentedControl仅在分段控件的样式为UISegmentedControlStyleBar时才使用此属性.

现在,范围栏分段控件看起来像UISegmentedControlStyleBar但不是,它是一些未记录的样式:

NSLog(@"scope bar style is %d", scopeBar.segmentedControlStyle);
> scope bar style is 7
Run Code Online (Sandbox Code Playgroud)

你可以尝试这个,它实际上设置了色调,但它看起来像屁股:

[scopeBar setSegmentedControlStyle:UISegmentedControlStyleBar];
[scopeBar setTintColor: UIColorFromRGB(0x990066)];
> scope bar style is 2
Run Code Online (Sandbox Code Playgroud)

在内部有一些影响这个的实例变量:_segementedControlFlags.style和_barStyle但你不能破解那些,除非你绕过认可的API.

最好的做法是与Apple一起提升它,并希望它们在未来版本中包含一个修复程序.