我正在尝试更改UISearchBar输入字段的背景颜色.这是您输入要搜索的文本的圆角视图,默认颜色为白色.我想把它改成灰色
我试过了:
for (UIView *subView in searchBar.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UITextField")]) {
UITextField *textField = (UITextField *)subView;
[textField setBackgroundColor:[UIColor grayColor]];
}
但它不起作用:(
我还尝试将图像视图插入TextField,但似乎圆角视图与TextField分开.那么,有什么线索吗?
解决方法
=)
for (UIView *subView in _searchBar.subviews) {
for(id field in subView.subviews){
if ([field isKindOfClass:[UITextField class]]) {
UITextField *textField = (UITextField *)field;
[textField setBackgroundColor:[UIColor grayColor]];
}
}
}