Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchbar barTintColor Cancel button not visible

I try to set the bar color of a UISearchbar to one color and the tintColor (cursor and Cancel-Button) to another color with code like this:

searchbar.barTintColor = color1;
searchbar.tintColor = color2;

The barTintColor is applied correctly.

The problem is: The text of the cancel button is not visible but if try the same in storyboard (apply batTintColor and tintColor to a UISearchbar) everything works as expected.

like image 246
mhaddl Avatar asked Oct 30 '13 19:10

mhaddl


1 Answers

I noticed that the cancel button is only not visible when it's state is "normal" so I found this code which solve the problem but I don't think this is the intended approach.

 [[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]    setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor greenColor]} forState:UIControlStateNormal];
like image 72
mhaddl Avatar answered Nov 08 '22 03:11

mhaddl