iOS TableView渐变效果

时间:2014-09-24 15:49:17

标签: ios xcode uitableview cocoa-touch uikit

我已经看过很多关于如何将渐变效果应用于TableView单元格的教程,但我想要实现的是用户选择基色然后在表格的所有单元格中创建渐变效果。与此类似:

http://realmacsoftware.com/clear/

如果有人对如何实现这一点有任何想法,那就太棒了!

1 个答案:

答案 0 :(得分:4)

您只需计算cellForRowAtIndexPath中的每种颜色并将其设置在那里。

我掀起了一些伪造的代码给你一个想法。

- (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];

}