Reputation: 53
I have seen many tutorials about how to apply a gradient effect to a cell of a TableView but what I wanted to achieve was for a user to select a base color and then create a gradient effect across all the cells of the table. Similar to this:
http://realmacsoftware.com/clear/
If anyone has any ideas about how to achieve this, that would be great!
Upvotes: 1
Views: 300
Reputation: 1491
You will just have to calculate each color in your cellForRowAtIndexPath: and set it there.
some fake code i whipped up to give you an idea.
- (UIColor *)colorForRow:(NSInteger)row withTotalRows:(NSInteger)totalRows {
// code to calculate the colors, you can use total rows to insure the end color.
// You will want to calculate the percentage of each color for your gradient.
return color;
}
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Get your cell first
NSInteger totalRows = [self numberOfRowsInSection:indexPath.section];
cell.contentView.backgroundColor = [self colorForRow:indexPath.row withTotalRows:totalRows];
}
Upvotes: 4