我在导航栏的标题视图中有一个 UISearchBar,我确实使用了 [searchBar sizetofit] 并创建了带有 CGRectZero 框架的 UISearchBar。但是Navigation的titleView里面的UISearchBar的左右大小有一个小的空白区域。
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 完全填充纵向和横向屏幕的宽度..
非常感谢任何帮助:)
我在 iPhone 5 上使用 Xcode 4.5、iOS 6。
我只想使用 navigationItem.titleView 来托管我的 UISearchBar,我认为这样更好。
谢谢大家