Search code examples
iosswiftxcodesearchcursor

XCODE: How do I hide the cursor from my searchBar after the user is done searching?


I have looked tirelessly through SO and haven't found out how to do this. How do I hide the cursor from my searchBar after the user is done searching? It just keeps blinking when the user doesn't need it to.


Solution

  • For normal UITextFields, if you set the tintColor property to .clear, the cursor will hide. Similarly, for a UISearchBar, I would try

    let sb = UISearchBar()
    sb.searchTextField.tintColor = .clear
    

    OR

    let sb = UISearchBar()
    sb.tintColor = .clear
    

    Let me know if it works.