现在的位置: 首页 > 综合 > 正文

IOS-UITableViewCell的渐变色

2018年02月02日 ⁄ 综合 ⁄ 共 970字 ⁄ 字号 评论关闭
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
    
    CAGradientLayer *grad = [CAGradientLayer layer];
    grad.frame = cell.bounds;
    grad.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:52.0f/255.0f green:50.0f/255.0f blue:51.0f/255.0f alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:35.0f/255.0f green:34.0f/255.0f blue:34.0f/255.0f alpha:1.0f] CGColor], nil];
    
    [cell setBackgroundView:[[UIView alloc] init]];
    [cell.backgroundView.layer insertSublayer:grad atIndex:0];
    
    CAGradientLayer *selectedGrad = [CAGradientLayer layer];
    selectedGrad.frame = cell.bounds;
    selectedGrad.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
    
    [cell setSelectedBackgroundView:[[UIView alloc] init]];
    [cell.selectedBackgroundView.layer insertSublayer:selectedGrad atIndex:0];
}

转自https://coderwall.com/p/tolkaa/uitableview-cells-background-gradient-ios-objective-c

抱歉!评论已关闭.