我正在尝试向自定义单元格的背景添加渐变,当我使用 addSublayer 显示渐变时,它会显示在其余内容上,而当我使用 insertSublayer: atIndex: 0 时,它不会出现。此单元格是自定义单元格,我该怎么办?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ScoreCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = cell.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor yellowColor]CGColor], (id)[[UIColor whiteColor]CGColor], nil];
[cell.layer insertSublayer:gradient atIndex:1];
return cell;
}