ios - iOS TableView渐变效果

标签 ios xcode uitableview cocoa-touch uikit

我看过很多关于如何对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];

}

关于ios - iOS TableView渐变效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26021265/

相关文章:

ios - 无法在 UITableViewController 中设置 TableView 的约束

iOS - 在 main() 中捕获异常

ios - 成功构建后 Xcode 没有存档

ios - 删除 UITableView 中 UITableViewCells 之间的行

ios - 用于 iPad 的 UITableViewCell

objective-c - 允许用户编辑 UITableView 单元格中的文本

ios - 第二次启动应用程序只显示黑色 View

objective-c - 错误 '!dat'

ios - 格式错误或损坏的 AST 文件 : 'Unable to load module "/Library/Developer/Xcode/DerivedData/ModuleCache/34OBPFY26OANR/Darwin. pcm“:找不到文件”

ios - 移动键盘时出现黑色区域