Cursor invisible in UISearchBar iOS 7

南笙酒味 提交于 2019-11-28 13:20:03

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.

pulkit

try using with

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

}

hope this will help you

Try setting text field tint color using UIAppearance

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor: [UIColor darkGrayColor]];

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:

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

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 .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!