我自定义 tableview 的单元格。单元格包括2个按钮(一个是红色,另一个是蓝色)。但是当我选择单元格时,2个按钮将背景颜色更改为突出显示的单元格颜色。我希望他们在突出显示单元格时保持颜色。我的解决方案是捕获tableview
突出显示的委托并更改按钮的背景。
任何人都可以给我另一种解决方案吗?
由于
答案 0 :(得分:1)
您必须覆盖setHighlighted
子类中的setSelected
和UITableViewCell
目标C
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
UIColor *someViewColor = self.someView.backgroundColor;
[super setHighlighted:highlighted animated:animated];
self.someView.backgroundColor = someViewColor;
}
-(void)setSelected:(BOOL)selected animated:(BOOL)animated
{
UIColor *someViewColor = self.someView.backgroundColor;
[super setSelected:selected animated:animated];
self.someView.backgroundColor = someViewColor;
}
<强>夫特强>
override func setHighlighted(highlighted: Bool, animated: Bool) {
let someViewColor = someView.backgroundColor
super.setHighlighted(highlighted, animated: animated)
someView.backgroundColor = someViewColor
}
override func setSelected(selected: Bool, animated: Bool) {
let someViewColor = someView.backgroundColor
super.setSelected(selected, animated: animated)
someView.backgroundColor = someViewColor
}