我有 UITableView 和 customCell(CustomCell 有 2 个标签和一个 ImageView)。
在正常模式下,我需要所有单元格的白色。
如果用户按下特定单元格,则该单元格的颜色应为灰色(其余单元格应为白色)
如果用户释放相同的单元格,该单元格的颜色应为橙色(其余单元格应为白色)
我怎样才能弄清楚?
我已经尝试使用 setSelectedBackground、willSelectRowAtIndexPath 和 Gestures 方法。但看不到同一个单元格的这 3 种颜色状态。这两个州中的任何一个都在合作。
知道如何实现相同的功能吗?
我已经使用选择器在 android 中实现了相同的功能。我希望 iPhone 具有相同的功能。有什么帮助吗?
提前致谢!
最佳答案
在自定义单元格中写入这两个方法
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
self.contentView.backgroundColor=[UIColor greenColor];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
self.contentView.backgroundColor=[UIColor orangeColor];
}
关于iphone - 在按下状态和选择状态时更改 UITableViewCell 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15199687/