2
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.

4

0 に答える 0