In iOS 7.x we were able to use
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil]
setDefaultTextAttributes:@{NSForegroundColorAttributeName:myColor}];
But it got deprecated in iOS 9. The only solution I know - is to iterate through subview hierarchy of UISearchBar
, look for UITextField
and change its properties. But this way is considered as Private API Usage
Do we have legal way to change UISearchBar text color in iOS 9.x?
You now need to use appearanceWhenContainedInInstancesOfClasses:
For example:
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTextColor:[UIColor whiteColor]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With