Alex Rivera | Logout

Different background colors for the top and bottom of a UITableView

Asked 2009-07-11T20:37:24.340
36

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.

Edit
Report

1 Answer

3

This might not be a "best practice," but if you really want to do it like Apple, there's a private UITableView property called tableHeaderBackgroundColor. The grayish color is #e2e7ed.

You could put something like this in the -viewDidLoad method of a UITableViewController:

UIColor *grayishColor = [UIColor colorWithRed:226/255.0
                                        green:231/255.0
                                         blue:237/255.0 alpha:1.0];
[self.tableView setValue:grayishColor forKey:@"tableHeaderBackgroundColor"];
answered 2009-10-25T05:29:43.090

Your Answer