iOS TableView渐变效果
问题描述:
我见过很多关于如何将渐变效果应用于TableView的单元格的教程,但我想要实现的是让用户选择基本颜色,然后在所有单元格中创建渐变效果的表格。与此相似:iOS TableView渐变效果
http://realmacsoftware.com/clear/
如果任何人有关于如何实现这一目标的任何想法,这将是伟大的!
答
你只需要计算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];
}
谢谢你,会放弃它! – user3744562 2014-09-24 18:00:32