[英]Set rounded corners and border to background(Not the UITextField) of UISearchBar in ios7
How can i apply rounded corners and a border to the background of UISearchBar in ios7? 如何在ios7中将圆角和边框应用于UISearchBar的背景? I am able to change the background color of the bar.
我可以改变条形图的背景颜色。
Something like this 像这样的东西
Thanks 谢谢
UISearchBar *searchBar = [[UISearchBar alloc] init];
searchBar.layer.cornerRadius = 6;
searchBar.clipsToBounds = YES;
[searchBar.layer setBorderWidth:1.0];
[searchBar.layer setBorderColor:[[UIColor lightGrayColor].CGColor];
For making the search bar round rect use this: 要使搜索栏成为圆形,请使用:
for (UIView *searchBarSubview in [mySearchBar subviews]) {
if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) {
@try {
[(UITextField *)searchBarSubview setBorderStyle:UITextBorderStyleRoundedRect];
}
@catch (NSException * e) {
// ignore exception
}
}
}
For changing background color use this: 要更改背景颜色,请使用:
yourSearchBar.barTintColor = [UIColor redColor]; // Use you necessary color.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.