Cursor invisible in UISearchBar iOS 7

后端 未结 6 923
攒了一身酷
攒了一身酷 2020-12-11 15:04

I have UISearchBar in UITableView as a table header. When I push the UISearchBar for start searching, this method is being triggered

相关标签:
6条回答
  • 2020-12-11 15:45

    Cursor in the search bar takes color from Search Bar -> View -> Tint Color property. In your case, it is set to White color, so it becomes invisible.

    0 讨论(0)
  • 2020-12-11 15:46

    try using with

    -(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
    {
        self.navigationItem.titleView.tintColor = [UIColor blueColor];
    
    }
    

    hope this will help you

    0 讨论(0)
  • 2020-12-11 15:46

    Try setting text field tint color using UIAppearance

    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor: [UIColor darkGrayColor]];
    
    0 讨论(0)
  • 2020-12-11 15:46

    If you want the cursor and cancel button to be different colors...


    Start by setting the view's tint color (not the bar tint) in the storyboard editor, which will be applied to both the cursor and cancel button.


    To make the cursor a different color, you need to do it programatically. The text field is nested a couple levels down in the searchBar's subviews. Use this setTextFieldTintColor helper function to traverse all of the subviews.

    @IBOutlet weak var searchBar: UISearchBar!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        // set tint color for all subviews in searchBar that are of type UITextField
        setTextFieldTintColor(to: UIColor.darkText, for: searchBar)
    }    
    
    func setTextFieldTintColor(to color: UIColor, for view: UIView) {
        if view is UITextField {
            view.tintColor = color
        }
        for subview in view.subviews {
            setTextFieldTintColor(to: color, for: subview)
        }
    }
    

    The end result looks like this:

    0 讨论(0)
  • 2020-12-11 15:53

    Your cursor is white because your tintColor property on UISearchBar is set to white.

    If you want Cancel btn to be white, but cursor to be black you can use: UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).tintColor = .black

    0 讨论(0)
  • 2020-12-11 16:01

    Try this it's only one line of code to solve your problem , Change cursor tintColor property white to blue.

      searchBar.tintColor = [UIColor blueColor];
    

    Hope this will help to someone .

    0 讨论(0)
提交回复
热议问题