0

I have changed the search bar placeholder color to blue and text color to white. Normal conditions works fine.

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
 [[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor colorWithRed:131/255.0 green:169/255.0 blue:202/255.0 alpha:1.0] ];
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setBackgroundColor:[UIColor colorWithRed:42/255.0 green:93/255.0 blue:134/255.0 alpha:1.0]];

Issue When I set Text

 self.searchbar.text = @"Some text";

The text displayed in search bar takes the placeholder color i.e blue but i want it to take white.

1 Answers1

0

Instead of "UILabel" for your text color, use "UITextField":

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor colorWithRed:131/255.0 green:169/255.0 blue:202/255.0 alpha:1.0]];

And more information can be found in the answers of this related question.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215