Different background colors for the top and bottom of a UITableView

iphone, uitableview

Solution

The easiest and most lightweight way to solve this problem is:

- Set the background color of the table view to whatever you want - in your case, white.

- Put the search bar view inside a container view. Set the table view's header view to this container view (instead of the search bar view itself, which is probably what you were doing previously).

- In that container view, add another subview with frame equal to a rect like (0, -480, 320, 480), and set the background color of that subview to whatever color you want - in your case, grayish.

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.

Problem

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. I can think of a couple ways of solving this problem, but they're pretty hacky: - Change the table view's background color depending on the current scrollOffset by overriding -scrollViewDidScroll: - Give the UITableView a clear background color and then set its superview's backgroundColor to a gradient pattern image. Does anyone know what the "best practice" solution is for this problem? thanks.

Original source

Related problems