UISearchBAR scopeBar tintColor

后端 未结 8 1958
小蘑菇
小蘑菇 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:33

    This solution is in Swift, can be adapted to objective-c. You can find the segmented control view using below function

    func findSegmentedControl(view : UIView) -> UIView? {
        for v in view.subviews {
            if v is UISegmentedControl {
                print(v)
                return v
            } else {
                if let found = findSegmentedControl(view : v) {
                    return found
                }
            }
        }
        return nil
    }
    

    and then set tint color of the view. calling this function will be like this:

    if let segmentedView = findSegmentedControl(view: searchController.searchBar) {                
                segmentedView.tintColor = UIColor.white
            }
    

提交回复
热议问题