目前我正在尝试使用以下代码更改分组 UITableViewCell (非子类)的背景选择颜色:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor yellowColor];
}
出现以下问题:
也试过:
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width - 17, cell.frame.size.height-3)];
cell.selectedBackgroundView.backgroundColor = coolBlue;
UIBezierPath *rounded;
rounded = [UIBezierPath bezierPathWithRoundedRect:cell.selectedBackgroundView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(8.0f, 8.0f)];
else
rounded = [UIBezierPath bezierPathWithRoundedRect:cell.selectedBackgroundView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(8.0f, 8.0f)];
CAShapeLayer *shape = [[CAShapeLayer alloc] init];
[shape setPath:rounded.CGPath];
cell.selectedBackgroundView.layer.mask = shape;
当我尝试使用上面的代码时,当我尝试从高度减去 3 时,单元格底部的部分被切断。我减去 3 个像素以保持分隔线。