Invisible cursor in UISearchBar iOS 7

I have a UISearchBar in a UITableView as a table title. When I click UISearchBar to start the search, this method starts

 - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar 

for UISearchDisplayController .

But the result is this:

As you can see, there is no cursor, I can start typing and searching, everything works fine. It is also invisible only in iOS 7. However, with iOS 6.1 and iOS 7.1 Beta 3, I could see the cursor. So, how can I make the UISearchBar cursor visible or how can I add a cursor to my UISearchBar?

+11
ios7 uisearchbar uisearchdisplaycontroller
Jan 30 '14 at 10:27
source share
5 answers

The cursor in the search bar accepts color from the search bar → View → Hue color property. In your case, it is white, so it becomes invisible.

+11
Mar 04 '14 at 19:55
source share

try using with

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

hope this helps you

+7
May 5 '14 at 6:12
source share

Try setting the hue color of the text box using UIAppearance

 [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor: [UIColor darkGrayColor]]; 
+5
Jul 13 '15 at 10:10
source share

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




Start by setting the color of the hue of the view (not the hue) in the storyboard editor, which will apply to both the cursor and the cancel button.

UISearchBar in a storyboard editor with a simulator.




To make the cursor a different color, you need to do it programmatically. Text box of nested levels in nested searchBar objects. Use this helper function setTextFieldTintColor to move all subzones.

 @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 is as follows:

UISearchBar with different colored cursor and cancel button.

+1
Feb 24 '17 at 17:37
source share

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

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

0
Feb 16 '18 at 12:34
source share



All Articles