Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the UISearchBar search text color?

How can I change the text color of a UISearchBar?

like image 671
MrTourkos Avatar asked Feb 13 '15 12:02

MrTourkos


People also ask

How do I change the placeholder color in Swift searchBar?

Try this: UITextField *searchField = [searchbar valueForKey:@"_searchField"]; field. textColor = [UIColor redColor]; //You can put any color here.


1 Answers

You have to access the UITextField inside the UISearchBar. You can do that by using valueForKey("searchField")

var textFieldInsideSearchBar = yourSearchbar.valueForKey("searchField") as? UITextField  textFieldInsideSearchBar?.textColor = yourcolor 

Swift 3 update

let textFieldInsideSearchBar = yourSearchbar.value(forKey: "searchField") as? UITextField  textFieldInsideSearchBar?.textColor = yourcolor 
like image 111
Christian Avatar answered Oct 28 '22 05:10

Christian