NavigationController 上自定义searchBar

效果

NavigationController 上自定义searchBar_第1张图片
self.navigationController.navigationBar.backgroundColor= [UIColorgreenColor];
UIView*titleView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,selfWidth-70,35)];
UISearchBar*searchBar = [[UISearchBaralloc]init];
searchBar.delegate=self;
searchBar.frame=CGRectMake(0,0,selfWidth-70,35);
searchBar.layer.cornerRadius=18;
searchBar.layer.masksToBounds=YES;
//边框线粗细
[searchBar.layersetBorderWidth:8];
//设置边框为白色是为了盖住UISearchBar上的灰色
[searchBar.layersetBorderColor:[UIColorwhiteColor].CGColor];
searchBar.placeholder=@"搜索你想要的东西";
[titleViewaddSubview:searchBar];
self.navigationItem.titleView= titleView;

你可能感兴趣的:(NavigationController 上自定义searchBar)