我在导航栏的titleView中有一个UISearchBar,我没有使用[searchBar sizetofit]并创建带有CGRectZero框架的UISearchBar。但是在导航的titleView中,UISearchBar的左右尺寸上有一个很小的空白空间。UINearchBar在UINavigationItem.titleView中没有完全填充宽度
theSearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
theSearchBar.delegate = self;
self.navigationItem.titleView = self.theSearchBar;
[self.theSearchBar sizeToFit];
self.navigationItem.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
//Change color of UISearchBar
theSearchBar.tintColor = [UIColor colorWithRed:102.0f/255.0f green:73.0f/255.0f
blue:126.0f/255.0f alpha:1.0f];
//Change color of NavigationBarItem
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:102.0f/255.0f
green:73.0f/255.0f blue:126.0f/255.0f alpha:1.0f];
//Set background image for navigation bar
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:
@"SearchBar.png"] forBarMetrics:UIBarMetricsDefault];
我想的UISearchBar完全填满屏幕的宽度,纵向和横向..
任何帮助,非常感谢:)
进出口使用的Xcode 4.5, iOS 6,与iPhone 5.
我只想使用navigationItem.titleView托管我的UISearchBar,我认为它更好的方式。
感谢所有
我试过这个,但是searchBar并没有在横向视图中扩展它的大小。当用户旋转时,如何扩展和缩回?你如何从导航栏中删除它的子视图? –
我把它与autarchizingmask为herearchbar :)并将其隐藏在视图中消失。谢谢 –