查了很多资料没有找到办法,就用了下面的方法
将UISearchBar放到view中,并且将view的边角裁剪一下就好了
UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 30)];
titleView.backgroundColor = [UIColor clearColor];
UISearchBar *search = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 200, 30)];
[titleView addSubview:search];
search.tintColor = [UIColor grayColor];
search.placeholder = @"请输入你的关键词";
self.navigationItem.titleView = titleView;
titleView.layer.cornerRadius = 5;
titleView.clipsToBounds = YES;