【问题标题】:iOS TableView Gradient EffectiOS TableView 渐变效果
【发布时间】:2014-11-19 04:54:19
【问题描述】:

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

http://realmacsoftware.com/clear/

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

【问题讨论】:

    标签: ios xcode uitableview cocoa-touch uikit


    【解决方案1】:

    您只需计算 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];
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-02
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-06
      相关资源
      最近更新 更多