如何在ios7中将圆角和边框应用于UISearchBar的背景?我可以改变条形图的背景颜色。
像这样的东西
由于
答案 0 :(得分:12)
UISearchBar *searchBar = [[UISearchBar alloc] init];
searchBar.layer.cornerRadius = 6;
searchBar.clipsToBounds = YES;
[searchBar.layer setBorderWidth:1.0];
[searchBar.layer setBorderColor:[[UIColor lightGrayColor].CGColor];
答案 1 :(得分:0)
要使搜索栏成为圆形,请使用:
for (UIView *searchBarSubview in [mySearchBar subviews]) {
if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) {
@try {
[(UITextField *)searchBarSubview setBorderStyle:UITextBorderStyleRoundedRect];
}
@catch (NSException * e) {
// ignore exception
}
}
}
要更改背景颜色,请使用:
yourSearchBar.barTintColor = [UIColor redColor]; // Use you necessary color.