UITableView实现行纵向颜色渐变

实现效果如下:

其实实现很简单,开始觉得使用颜色值和tableView的indexPath.row挂钩使用即可

或者使用CAGradientLayer实现渐变

最后使用alpha实现即可。需要注意的是alpha的值大小和行数(或者section值相反)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ColorGradientCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ColorGradientCell" forIndexPath:indexPath];
    cell.titileLabel.font = [UIFont systemFontOfSize:15];
    cell.titileLabel.text = @"思思";
    cell.tipLabel.text = [NSString stringWithFormat:@"%ld", indexPath.section + 1];
    // 透明度来实现渐变
    cell.tipLabel.alpha = (tableView.numberOfSections - indexPath.section) * 0.2;
    return cell;
}

有更好的实现方式可以留言告知哟。。。

posted on 2018-02-27 15:20  玉思盈蝶  阅读(1012)  评论(0编辑  收藏  举报

导航