【发布时间】:2013-08-27 17:46:56
【问题描述】:
我的导航控制器栏标题视图中有一个 UISearchBar。我在这里遵循了第一个答案How to add search bar in navigation bar for iphone?。这对我有用,但搜索栏的尺寸是硬编码的。如何设置尺寸,使其在 iPad 和 iPhone 上的纵向和横向模式都好看?
这是我的搜索栏控制器中的代码。
self.view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 310.0, 44)];
self.view.autoresizingMask = 0;
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(-5.0, 0.0, 320.0, 44.0)];
_searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_searchBar.delegate = self;
[self.view addSubview:_searchBar];
然后在我的主视图控制器中我有
self.navigationItem.titleView = _searchController.view;
【问题讨论】:
-
显示将搜索栏添加到导航栏的代码。
标签: ios