Search code examples
uitableviewios7

Are there any way to set the UITableView section header color in iOS 7 directly rather creating a new UIView


UITableView's section headers are less identifiable in iOS 7. Are there any way to set the UITableView section header color in iOS 7 directly rather creating a new UIView.

enter image description here

Note: I found some solutions by creating a new UIView in,

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

but I really wanted to keep the Apple's properties except color. Are there any way to do it without this method.


Solution

  • Implement tableView:willDisplayHeaderView:forSection: and update the view that you are passed.

    - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
    {
        UITableViewHeaderFooterView *v = (UITableViewHeaderFooterView *)view;
        v.backgroundView.backgroundColor = [UIColor darkGrayColor];
    }
    

    (assuming that you supplied a UITableViewHeaderFooterView instance in your implementation for tableView:viewForHeaderInSection:)