1
我需要自定义部分部分,其中包含分组的风格的UITableView的几个单元格。实际上,我想为单元格的每个部分设置渐变颜色背景。每个部分的单元格数目可能会更改。如何为分组单元格的UITableView部分绘制渐变色背景
我发现很多解决方案为每个单元定制一个背景,但不定制一个单元格区域。
为为例,下面的代码设置背景颜色每每个部分的单元:
-(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 whiteColor] CGColor], (id)[[UIColor greenColor] CGColor], nil];
grad.cornerRadius = 5.0;
[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];
}
这不是我需要实现,我必须设置的线性梯度颜色所有单元为每个部分。
如果有谁面临着同样的问题,并发现了一个解决方案,请让我们知道
非常感谢