[英]iOS / iPhone - setting the color of an arbitrary row
我正在尝试使用以下代码在UITableView中设置所选行的颜色:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];
}
}
问题是,它正在所有行上设置颜色。 此外,当我选择特定行时,它会以蓝色突出显示该行。 如何获得以红色突出显示所选行的信息?
对我来说,最简单的方法是将UITableViewCell
子类化并覆盖setSelected:
方法(如果需要,其他所有内容都保留相同)
一些来自旧项目的示例代码:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
UIView *bg = [[UIView alloc] initWithFrame:self.frame];
bg.backgroundColor = [UIColor colorWithRed:.916 green:.9648 blue:.9844 alpha:1.0];
self.selectedBackgroundView = bg;
[bg release];
// Configure the view for the selected state
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.