How to tint the sections in your UITableVIew

TableSectionsTo make those sections in a UITableView stand out a bit, you can give them a different colour tint.

Add a new method in your table view delegate and paint with numbers:

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    
    UIColor *pinkTint = [UIColor colorWithRed:0.7 green:0.5 blue:0.8 alpha:0.7];
    view.tintColor = pinkTint;
}

The above will create colours in RGB, and values between 0.0 and 1.0 are allowed.

Or, if you’d rather show a picture instead (as a pattern or because you have a nice colour swatch), grab it from your project and turn it into a colour like so:

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    
    UIColor *pinkTint = [UIColor colorWithRed:0.7 green:0.5 blue:0.8 alpha:0.7];
    view.tintColor = pinkTint;
}

– (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {

UIColor *niceColour = [UIColor colorWithPatternImage:[UIImage imageNamed:@”NiceColour”]];
view.tintColor = niceColour;
}





Leave a Reply