Change UISearchBar text color in iOS 9+

In iOS 7.x we were able to use

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil]
    setDefaultTextAttributes:@{NSForegroundColorAttributeName:myColor}];

But it is deprecated in iOS 9. The only solution I know is to iterate through the subview hierarchy UISearchBar, find UITextFieldand change its properties. But this method is considered as Private use of API

Do I have a legal way to change the text color of a UISearchBar in iOS 9.x?

+4
source share
1 answer

Now you need to use the appearance of WhenContainedInInstancesOfClasses:

For example:

[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTextColor:[UIColor whiteColor]];
0
source

Source: https://habr.com/ru/post/1613479/


All Articles