UISearchBar中控制UITextField圆角显示
//old code
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setCornerRadius:14.0];
//ios9
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setCornerRadius:14.f];
//设置字号
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setFont:[UIFont systemFontOfSize:16.f]];
完整代码
//设置圆角
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setCornerRadius:14.f];
UISearchBar * _searchBar = [UISearchBar new];
_searchBar.delegate = self;
_searchBar.placeholder = @"请输入关键字";
//uitextfield设置背景色
UIImage * searchBg = [[UIImage alloc] imageWithColor:[UIColor colorWithHex:0xebebeb] withSize:CGSizeMake(1, 30)];
[_searchBar setSearchFieldBackgroundImage:searchBg forState:UIControlStateNormal];
_searchBar.barTintColor = [UIColor colorWithHex:0xff00000];
self.navigationItem.titleView = _searchBar;
//navigationbar设置背景颜色及状态栏颜色
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;