UISearchBAR scopeBar tintColor [英] UISearchBAR scopeBar tintColor
问题描述
是否有人设法为 UISearchBar 的范围栏部分着色,它有一个 tintColor 属性,但设置它不会影响附加的范围栏 UISegmentedControl.我有一个把手可以给它上色,但似乎不起作用,即:
Has anyone managed to color the scopebar portion of a UISearchBar, it has a tintColor property but setting it does not affect the attached scopebar UISegmentedControl. Ive got a handle on the bar to tint it but doesnt seem to work ie:
for (id subview in searchBar.subviews){
if([subview isMemberOfClass:[UISegmentedControl class]]){
UISegmentedControl *scopeBar=(UISegmentedControl *) subview;
scopeBar.tintColor=UIColorFromRGB(0x990066);
}
}
干杯,尼尔
推荐答案
这很有趣,原来范围栏是一个有点自定义的分段控件.
This is interesting, turns out the scope bar is a somewhat customised segmented control.
来自文档:UISegmentedControl 仅在分段控件的样式为 UISegmentedControlStyleBar 时使用此属性.
From the docs: UISegmentedControl uses this property only if the style of the segmented control is UISegmentedControlStyleBar.
现在范围栏分段控件看起来像 UISegmentedControlStyleBar 但不是,它是一些未记录的样式:
Now the scope bar segmented control looks like UISegmentedControlStyleBar but isn't, it's some undocumented style:
NSLog(@"scope bar style is %d", scopeBar.segmentedControlStyle);
> scope bar style is 7
你可以试试这个,它确实设置了色调,但看起来像屁股:
You can try this, which does actually set the tint but it looks like arse:
[scopeBar setSegmentedControlStyle:UISegmentedControlStyleBar];
[scopeBar setTintColor: UIColorFromRGB(0x990066)];
> scope bar style is 2
在内部有一些实例变量会影响此:_segementedControlFlags.style 和 _barStyle 但除非绕过受制裁的 API,否则您无法破解它们.
Internally there are some instance variables influencing this: _segementedControlFlags.style and _barStyle but you cannot hack those unless you bypass the sanctioned API.
最好的做法是向 Apple 提出该问题,并希望他们在未来的版本中包含修复程序.
The best course of action is to raise it with Apple and hope they include a fix in a future release.
这篇关于UISearchBAR scopeBar tintColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!