0
我有一个表格视图,如何选择不同颜色的单元格?或者我如何设置选择的图像?感谢UITableView,选择颜色与蓝色不同的单元格?
我有一个表格视图,如何选择不同颜色的单元格?或者我如何设置选择的图像?感谢UITableView,选择颜色与蓝色不同的单元格?
你可以很容易地改变细胞中选择风格为灰色:
[myTableView setSelectionStyle: UITableViewCellSelectionStyleGray];
或者你可以在willDisplayCell
委托改变contentView's
backgroundColor
:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];
}
另一种方法是创建一个自定义单元格并更改背景的颜色。
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor redColor]];
[cell setSelectedBackgroundView:bgColorView];
[bgColorView release];
想必你可以做同样的一个UIImageView以及
UIImageView *bgImageView = [[UIImageView imageNamed:@"Your Image"];
[cell setSelectedBackgroundView:bgImageView];
[bgImageView release];
感谢),但在init方法内CustomCell类[自我setSelectionStyle:...] –