【问题标题】:iOS: dimensions of search bar in navigation controlleriOS:导航控制器中搜索栏的尺寸
【发布时间】: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


【解决方案1】:

有很多方法可以做到这一点,这里有一些文章可能会有所帮助:

  1. Get the device's orientation,然后相应地使用不同的值集
  2. Figure out which device the app is running on
  3. Get the dimension of the screen

【讨论】:

  • 有没有办法简单地以编程方式完成?喜欢使用自动调整大小和导航栏尺寸?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-12
  • 2018-01-03
  • 1970-01-01
相关资源
最近更新 更多