Cursor not displaying in UISearchBar for our app

Ios7UisearchbarUisearchbardisplaycontrol

Ios7 Problem Overview


For the UISearchBars in our app, there's no cursor shown in the bar with focus when running under iOS 7. How do we make that show?

We are using the SDK 7, with a minimum target of 6. We do have the translucency off for the navigation bars, and set the color at runtime. I can't think of anything else we are doing differently.

Ios7 Solutions


Solution 1 - Ios7

Our problem was that the tint color was set to white, so I didn't see it.

Solution 2 - Ios7

Set

searchBar.tintColor = [UIColor blueColor];

Solution 3 - Ios7

In the searchbox property window

open View Section>Set Tint color - default.

enter image description here

Hope this will help.

Solution 4 - Ios7

This is how it can be done in Swift :

override func viewWillAppear(animated: Bool) {
    self.searchBar.tintColor = UIColor.whiteColor()
    
    let view: UIView = self.searchBar.subviews[0] as! UIView
    let subViewsArray = view.subviews
    
    for (subView: UIView) in subViewsArray as! [UIView] {
        println(subView)
        if subView.isKindOfClass(UITextField){
            subView.tintColor = UIColor.blueColor()
        }
    }
    
}

Solution 5 - Ios7

searchBar.tintColor = view.tintColor  // self.view usually has the proper tintColor

Better than .blue or whatever.

Solution 6 - Ios7

Just set the tintColor for UISearchBar, in your storyboard, xib or code. Xcode seems to ignore the default tintColor.

Solution 7 - Ios7

You could loop through the searchBars subviews and obtain the uitextfield subview and set its @"insertionPointColor" value to your desired color. Works but is private api

for (UIView *subView in self.searchBar.subviews) {
    if ([subView isKindOfClass:[UITextField class]]) {
        [[(UITextField *) subView valueForKey:@"textInputTraits"] setValue:[UIColor blackColor] forKey:@"insertionPointColor"];
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJason HockerView Question on Stackoverflow
Solution 1 - Ios7Jason HockerView Answer on Stackoverflow
Solution 2 - Ios7MannView Answer on Stackoverflow
Solution 3 - Ios7Ram SView Answer on Stackoverflow
Solution 4 - Ios7BenjaminView Answer on Stackoverflow
Solution 5 - Ios7Dmitry IsaevView Answer on Stackoverflow
Solution 6 - Ios7Madson CardosoView Answer on Stackoverflow
Solution 7 - Ios7ClemensLView Answer on Stackoverflow