UITableView节索引与搜索栏重叠 [英] UITableView section index overlaps search bar

查看:210
本文介绍了UITableView节索引与搜索栏重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:我想在UITableView中显示一个节索引,并在表视图标题(而不是节标题)中使用搜索栏。
但是索引条现在与搜索栏重叠。有没有一个优雅的解决方案来避免这一点,让索引从表头下面开始?

Hi: I want to display a section index in an UITableView with a search bar in the table view header (not section header). But the index strip is now overlapping the search bar. Is there an elegant solution to avoid this and let the index start below the table header?

推荐答案

,但我有同样的问题,在这里和其他地方搜索。我在这里找到了好的答案:
更改UISearchBar TextField的大小?

I realize this answer comes very late, but I had the same problem and searched here and elsewhere. I found good answers here: Changing the size of the UISearchBar TextField?

有几个建议,但我发现最简单的是在UIView中放置一个UISearchBar和UINavBar,并将该视图传递给setTableView。问题是,表控制标头视图的大小,忽略您添加的任何设置。所以添加视图使得表愉快,您可以到达内部并设置搜索栏大小,而不受表干扰。UINavBar具有与UISearchBar相同的背景样式,因此以视觉上一致的方式填充额外的空间,你必须调整其框架 - 见下面:

There are several suggestions, but the one I found most straightforward was to put a UISearchBar and UINavBar in a UIView and pass that view to setTableView. The problem is that the table controls the size of the header view, ignoring any setting you add. So adding the view makes the table happy and you can reach inside and set the search bar size without being interfered with by the table.The UINavBar has the same background styles as the UISearchBar, so fills the extra space in a visually consistent way, though you have to tweak its frame - See below:

UISearchBar searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0, 1, 290, 40)] autorelease];
UIView *searchView = [[[UIView alloc] initWithFrame:CGRectMake(0, 1, 320, 40)] autorelease];
UINavigationBar *navBar = [[[UINavigationBar alloc] initWithFrame:CGRectMake(1, -1, 320, 41)] autorelease]; // same gradient/style as search bar
[navBar setTintColor:[UIColor lightGrayColor]];
[searchView addSubview:navBar];
[searchView addSubview:searchBar];

这篇关于UITableView节索引与搜索栏重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆