UISearchBAR scopeBar tintColor

后端 未结 8 1965
小蘑菇
小蘑菇 2021-02-02 15:46

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

8条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-02 16:31

    This is interesting, turns out the scope bar is a somewhat customised segmented control.

    From the docs: UISegmentedControl uses this property only if the style of the segmented control is 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
    

    Internally there are some instance variables influencing this: _segementedControlFlags.style and _barStyle but you cannot hack those unless you bypass the sanctioned API.

    The best course of action is to raise it with Apple and hope they include a fix in a future release.

提交回复
热议问题