Our problem was that the tint color was set to white, so I didn't see it.
Cursor not displaying in UISearchBar for our app
-
30-06-2022 - |
Question
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.
Solution
OTHER TIPS
Set
searchBar.tintColor = [UIColor blueColor];
In the searchbox property window
open View Section>Set Tint color - default.
Hope this will help.
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()
}
}
}
searchBar.tintColor = view.tintColor // self.view usually has the proper tintColor
Better than .blue
or whatever.
Just set the tintColor for UISearchBar, in your storyboard, xib or code. Xcode seems to ignore the default tintColor.
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"];
}
}