2012-11-02 26 views
1

我在导航栏的titleView中有一个UISearchBar,我没有使用[searchBar sizetofit]并创建带有CGRectZero框架的UISearchBar。但是在导航的titleView中,UISearchBar的左右尺寸上有一个很小的空白空间。UINearchBar在UINavigationItem.titleView中没有完全填充宽度

UISearchBar has empty on both side:

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,我认为它更好的方式。

感谢所有

回答

0

只要你可以隐藏导航栏,并添加theSearchBar到self.view self.navigationController.navigationBarHidden = NO; [self.view addSubview:theSearchBar];

+0

我试过这个,但是searchBar并没有在横向视图中扩展它的大小。当用户旋转时,如何扩展和缩回?你如何从导航栏中删除它的子视图? –

+0

我把它与autarchizingmask为herearchbar :)并将其隐藏在视图中消失。谢谢 –

0

只是在你的代码中添加以下两行的导航栏设置背景图片后:

[self.navigationItem setRightBarButtonItem:nil]; 
[self.navigationItem setLeftBarButtonItem:nil]; 

希望它为你工作。

+0

不幸的是它并没有解决问题:( –