【发布时间】:2012-11-05 16:37:54
【问题描述】:
在 iOS(支持 5.x+)中,将 UISearchBar 文本字段的白色背景颜色更改为不同颜色的最简单方法是什么?上面没有 tintColor 属性。
【问题讨论】:
标签: iphone objective-c ios search
在 iOS(支持 5.x+)中,将 UISearchBar 文本字段的白色背景颜色更改为不同颜色的最简单方法是什么?上面没有 tintColor 属性。
【问题讨论】:
标签: iphone objective-c ios search
你可以试试这个方法,
[searchBar setSearchFieldBackgroundImage: forState:];
在 iOS 5 之前的版本中,您可以将类别用作,
@implementation UISearchBar (BackgroundColor)
- (UITextField *)field {
// HACK: This may not work in future iOS versions
for (UIView *subview in self.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
return (UITextField *)subview;
}
}
return nil;
}
- (void)setTextBackgroundColor:(UIColor *)color {
self.field.backgroundColor = color;
}
@end
【讨论】: