我创建了一个自定义 UITableViewCell
。表格 View 显示数据正常。我遇到的问题是当用户触摸 tableview 的单元格时,我想显示单元格的背景颜色,而不是默认的 [蓝色] 值以突出显示单元格的选择。
我使用此代码,但没有任何反应:
cell.selectedBackgroundView.backgroundColor=[UIColor blackColor];
最佳答案
不需要自定义单元格。如果您只想更改单元格的选定颜色,可以这样做:
objective-C :
UIView *bgColorView = [[UIView alloc] init];
bgColorView.backgroundColor = [UIColor redColor];
[cell setSelectedBackgroundView:bgColorView];
swift :
let bgColorView = UIView()
bgColorView.backgroundColor = UIColor.red
cell.selectedBackgroundView = bgColorView
https://stackoverflow.com/questions/1998775/