我是 iOS 新手。我在我的表格视图中使用渐变。加载表格视图时,我可以使用渐变更改颜色。但是当它被选中时,我无法更改 tableview 单元格的颜色。我没有使用自定义单元格。请帮我。提前致谢
问问题
135 次
2 回答
1
在为 iOS 7 开发时,如果您不想要标准的单元格,则必须为单元格定义背景视图。
在您的方法tableView:cellForRowAtIndexPath:
中,请执行以下操作:
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = /* your customized color */ ;
bgColorView.layer.masksToBounds = YES;
cell.selectedBackgroundView = bgColorView;
创建细胞时。
于 2013-10-22T15:08:17.110 回答
0
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [cell setBackgroundColor:[UIColor clearColor]];
CAGradientLayer *grad = [CAGradientLayer layer];
grad.frame = cell.bounds;
grad.colors = [desired colors]
[cell setBackgroundView:[[UIView alloc] init]];
[cell.backgroundView.layer insertSublayer:grad atIndex:0];
CAGradientLayer *selectedGrad = [CAGradientLayer layer];
selectedGrad.frame = cell.bounds;
selectedGrad.colors = desired colors
[cell setSelectedBackgroundView:[[UIView alloc] init]];
[cell.selectedBackgroundView.layer insertSublayer:selectedGrad atIndex:0];
}
于 2013-10-23T06:40:31.883 回答