在iOS 9+;
在iOS 7.x中,我们能够使用在iOS 9+;,ios,objective-c,swift,uikit,uisearchbar,Ios,Objective C,Swift,Uikit,Uisearchbar,在iOS 7.x中,我们能够使用 [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{NSForegroundColorAttributeName:myColor}]; 但它在iOS 9中被弃用了。我知道的唯一解决方案是遍历UISearchBar的子视图层次结构,查找UITextField并更改其属性。但这种方式被视为私有API使用 我们是否有在iOS
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil]
setDefaultTextAttributes:@{NSForegroundColorAttributeName:myColor}];
但它在iOS 9中被弃用了。我知道的唯一解决方案是遍历UISearchBar
的子视图层次结构,查找UITextField
并更改其属性。但这种方式被视为私有API使用
我们是否有在iOS 9.x中更改UI搜索栏文本颜色的合法方法?您现在需要在包含类实例时使用Appearance: 例如:
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTextColor:[UIColor whiteColor]];
仅仅因为它被弃用并不意味着你不能使用它(看看你是否被警告惹恼了)。根本没有这样的方法,至少在Swift
UIAppearance
协议中不包含这样的方法:没想到。。。也许这会有所帮助:迭代子视图层次结构根本不使用私有API。你这样做是安全的。唯一的问题是层次结构可以随时更改。