- (void)createSearchBarView {
UIView *titleView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,CGRectGetWidth([UIScreenmainScreen].bounds)-120,35)];
UIColor *color = self.navigationController.navigationBar.backgroundColor;
[titleView setBackgroundColor:color];
UISearchBar *searchBar = [[UISearchBaralloc]init];
searchBar.delegate =self;
searchBar.frame =CGRectMake(0,0,CGRectGetWidth(titleView.frame),35);
searchBar.backgroundColor = color;
searchBar.layer.cornerRadius =18;
searchBar.layer.masksToBounds =YES;
[searchBar.layersetBorderWidth:8];
[searchBar.layersetBorderColor:[UIColorwhiteColor].CGColor];
searchBar.placeholder = @"搜索商品";
[titleView addSubview:searchBar];
//Set to titleView
[self.navigationItem.titleViewsizeToFit];
self.navigationItem.titleView = titleView;
}
IOS技术交流群:129582174