在iOS 7.x中我们能够使用
[[UITextField appearanceWhenContainedIn:[UISearchBar class],nil] setDefaultTextAttributes:@{NSForegroundColorAttributeName:myColor}];
但它在iOS 9中已被弃用.我所知道的唯一解决方案是迭代UISearchBar的子视图层次结构,查找UITextField并更改其属性.但这种方式被视为私有API使用
解决方法
您现在需要使用appearanceWhenContainedInInstancesOfClasses:
例如:
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTextColor:[UIColor whiteColor]];