UITableView顶部和底部的不同背景颜色 [英] Different background colors for the top and bottom of a UITableView
问题描述
如果您在iPhone OS 3.0的邮件应用程序中查看收件箱,您会看到向下滑动在UISearchBar上方显示浅灰色背景颜色。
If you look at your Inbox in iPhone OS 3.0's Mail app, you'll see that swiping down displays a grayish background color above the UISearchBar.
现在,如果向下滚动到表格的底部,您会看到该端的背景颜色为白色。
Now, if you scroll down to the bottom of the table, you'll see that the background color at that end is white.
我可以想到几种解决这个问题的方法,但是它们非常hacky:
I can think of a couple ways of solving this problem, but they're pretty hacky:
- 通过覆盖-scrollViewDidScroll,根据当前的scrollOffset更改表视图的背景颜色:
- 为UITableView提供清晰的背景颜色,然后将其superview的backgroundColor设置为渐变模式图片。
有谁知道这个问题的最佳实践解决方案是什么?谢谢。
Does anyone know what the "best practice" solution is for this problem? thanks.
推荐答案
解决这个问题的最简单,最轻量级的方法是:
The easiest and most lightweight way to solve this problem is:
- 将表格视图的背景颜色设置为您想要的任何颜色 - 在您的情况下为白色。
- 将搜索栏视图放在容器视图中。将表视图的标题视图设置为此容器视图(而不是搜索栏视图本身,这可能是您之前所做的)。
- 在该容器视图中,添加带框架的另一个子视图等于(0,-480,320,480)这样的矩形,并将该子视图的背景颜色设置为您想要的任何颜色 - 在您的情况下,为浅灰色。
这应该是你需要做的全部。我自己做了这个并实现了我想要的外观,与Mail应用程序完全相同。使用scrollViewDidScroll是CPU资源的主要浪费,并且子类化UITableView非常混乱,IMO。
That should be all you need to do. I just did this myself and achieved the look I wanted, exactly the same as the Mail app. Using scrollViewDidScroll is a major waste of CPU resources, and subclassing UITableView is super messy, IMO.
这篇关于UITableView顶部和底部的不同背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!