ios7 searchBar in navigationBar cover rightbuttonItem

时间:2013-11-12 03:01:27

标签: ios ios7 uisearchbar

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。

0 个答案:

没有答案