Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to change text color in a search bar for iOS 7

I need to change the text color in an UISearchBar text field. I tried the two answers in this post:

UISearchBar text color change in iOS 7

But the text remains in its default gray color. I set that code in the viewDidLoad method. What can I be missing? Did somebody have this same problem?

Thanks

like image 431
AppsDev Avatar asked Oct 03 '22 12:10

AppsDev


2 Answers

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor blueColor]];

//This is done in Xcode 5.0 and its working btw i don't know whether it works with previous versions of Xcode or not....
// Also I wrote this method in viewDidLoad
like image 189
Mubin Mall Avatar answered Oct 11 '22 15:10

Mubin Mall


// Get the instance of the UITextField of the search bar
UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];

// Change search bar text color
searchField.textColor = [UIColor blueColor];
like image 38
Matthieu Riegler Avatar answered Oct 11 '22 13:10

Matthieu Riegler