UISearchBar *searchBar = [UISearchBar new];
searchBar.showsCancelButton = YES;
[searchBar sizeToFit];
searchBar.tintColor=[UIColor redColor];
searchBar.barTintColor=[UIColor clearColor];
searchBar.translucent=NO;
CGRect newFrame = searchBar.frame;
newFrame.size.width = CGRectGetWidth(newFrame)-self.navigationItem.rightBarButtonItem.width;
searchBar.frame = newFrame;
UIView *barWrapper = [[UIView alloc]initWithFrame:searchBar.bounds];
barWrapper.backgroundColor=[UIColor clearColor];
[barWrapper addSubview:searchBar];
self.navigationItem.titleView = barWrapper;
NSLog(@"titleview = %@",self.navigationItem.titleView.frame);
_searchBar=searchBar;
它总是覆盖rightButtonItem。如何设置它?_searchBar 不想改变。
self.navigationItem.rightBarButtonItem.width => 0。