Last Updated: December 26, 2018
·
9.543K
· e0d

UITableView cells background gradient (iOS, Objective c)

Фоновый градиент ячеек UITableView в iOS, Objective C

-(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:50.0/255.0 green:63.0/255.0 blue:86.0/255.0 alpha:1.0] CGColor], (id)[[UIColor colorWithRed:23.0/255.0 green:26.0/255.0 blue:29.0/255.0 alpha:1.0] 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];
}