War*_*ard 8 iphone cocoa-touch uitableview uisearchbar
当UISearchBar位于表头内时,如何更改UISearchBar的宽度,以使截面索引不与文本字段重叠?我想重新创建您在手机应用的联系人视图中找到的相同布局.
一种可能的解决方案是向tableHeaderView添加自定义视图.这就是我做的:
searchBar是我在头文件中声明的UISearchBar.我创建了一个UIView并为整个宽度添加了一个UINavigationBar,并在其上添加了简短的UISearchBar.然后,我最终将UIView分配给tableHeaderView.
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 290.0, 44.0)];
UIView *customTableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
UINavigationBar *dummyNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
[customTableHeaderView addSubview:dummyNavigationBar];
[customTableHeaderView addSubview:searchBar];
[dummyNavigationBar release];
self.tableView.tableHeaderView = customTableHeaderView;
[customTableHeaderView release];
Run Code Online (Sandbox Code Playgroud)
更优雅的解决方案是使用contentStretch属性拉伸UISearchBar.我仍然需要尝试并检查它是否有效.
归档时间: |
|
查看次数: |
5892 次 |
最近记录: |