Objective c 更改UITableView分组的selectioncolor
目前,我正在尝试使用以下代码更改分组UITableViewCell(非子类)的背景选择颜色:Objective c 更改UITableView分组的selectioncolor,objective-c,Objective C,目前,我正在尝试使用以下代码更改分组UITableViewCell(非子类)的背景选择颜色: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ... cell.selectionStyle = UITableViewCellSelectionStyleNone; } - (void)tableView:(UITab
- (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个像素以保持分隔线。您是否尝试过使用:
[cell setBackgroundColor:[UIColor yellowColor]];
这似乎对我有用,但我的tableView设置可能与您的不同。非常感谢!!我已经尝试了两周了!