In iOS 7, you need to confirm the level again to access the text field. Change your code as follows
for (UIView *subView in self.searchBar.subviews) { for (UIView *secondLevelSubview in subView.subviews){ if ([secondLevelSubview isKindOfClass:[UITextField class]]) { UITextField *searchBarTextField = (UITextField *)secondLevelSubview;
Note. This is not an open API.
OR
You can use the UIControls, Like property appearance.
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];
Note. Appearance proxy can be used for iOS 9.0+ Audio output

You can set tintcolor to apply to key elements in the search bar .
Use tintcolor to align foreground elements.
Use barTintColor to tint the background.
In iOS v7.0, all subclasses of UIView get their behavior for tintColor from the base class. See the tintColor talk at the UIView level for more information. Apple doc
Toseef Khilji Sep 27 '13 at 10:46 2013-09-27 10:46
source share