iOS7:UISearchBar范围按钮未对齐

时间:2014-01-31 11:51:58

标签: ios7 uisearchbar uisearchdisplaycontroller

好的,我遇到了另一个iOS7的怪异:

我正在以编程方式将一些范围按钮添加到UISearchdisplayController + UISearchBar到表格视图。

现在,如果我选择搜索字段,则范围按钮太大。如果我切换到横向,事情变得更糟,按钮严重错位。

这是我的代码(只有几行添加到标准'主要详细信息应用程序' - 模板):

- (void)viewDidLoad
{
    // ... 

    UISearchBar *searchBar = [[UISearchBar alloc] init];
    searchBar.showsScopeBar = YES;
    searchBar.scopeButtonTitles = @[@"one", @"two"];
    self.tableView.tableHeaderView = searchBar;
    self.mySearchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];

    // ... add delegate, datasource, irrelevant for this example
}

这就是它的样子:

enter image description here enter image description here

增加:
顺便说一下,如果我用IB挂钩,也会出现错位。按钮宽度是正确的。

有没有人有解决方法的想法?

1 个答案:

答案 0 :(得分:0)

更改用于实例化搜索栏的初始值设定项,例如UISearchBar * searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,320,44)] ;.似乎是与搜索栏的指定初始化程序相关的问题。

相关问题