无法在uisearchbar iOS8.4中更改uitextfield背景颜色

时间:2015-08-05 01:21:18

标签: ios objective-c uisearchbar

我正在尝试更改UITextFieldUISearchBar的背景颜色。为此,我尝试了以下内容:

- 这个简单的一行代码:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setBackgroundColor:[UIColor redColor]];

这个for循环:

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]];
        }
    }
}

和这段代码:

UITextField *txfSearchField = [_searchBar valueForKey:@"_searchField"];
txfSearchField.backgroundColor = [UIColor redColor];

我想避免更改UISearchBar的背景图像,那么iOS8的新解决方案是什么?我在堆栈上找不到合适的答案。

0 个答案:

没有答案