gpt4 book ai didi

ios - UITableViewCell 中的渐变出现在内容上

转载 作者:行者123 更新时间:2023-11-29 02:46:52 30 4
gpt4 key购买 nike

我正在尝试向自定义单元格的背景添加渐变,当我使用 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;
}

最佳答案

插入以下代码。请记住,子层是从后到前的顺序列出的:

cell.backgroundColor = [UIColor clearColor];
[cell.layer insertSublayer:gradient atIndex:0];

关于ios - UITableViewCell 中的渐变出现在内容上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25004509/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com