【发布时间】:2012-05-18 23:11:22
【问题描述】:
我已经实现了一个搜索栏,我想更改搜索栏的颜色。我该怎么做?
我试过了:
self.mySearchBar.backgroundColor = [UIColor redColor];
但没有成功。
更新(已解决):
在使用以下代码定义背景颜色之前,我必须删除默认背景颜色。
for (UIView *subview in mySearchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
...所以代码将是下一个:
for (UIView *subview in mySearchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
self.mySearchBar.backgroundColor = [UIColor redColor];
【问题讨论】:
-
这是我给出的答案,你应该选择我的答案作为正确的答案
标签: iphone objective-c xcode uisearchbar