问题描述:原来cell上控件 有背景色。一点击后,控件的背景色就没了。整个控件就像短暂消失了一样。 以label为示例:
解决办法:
在自定义cell的时候,在这两个方法里面都设置上该控件的原来设定的背景色即可,记得先调用父类的方法。
(void)setSelected:(BOOL)selected animated:(BOOL)animated
(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
代码示例(Objective-C):
-
(void)setSelected:(BOOL)selected animated:(BOOL)animated {
UIColor *originColor = label.backgroundColor;
[super setSelected:selected animated:animated];
label.backgroundColor = originColor;
}
-
(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
UIColor *originColor = label.backgroundColor;
[super setHighlighted:highlighted animated:animated];
label.backgroundColor = originColor;
}
代码示例(swift):
import UIKit
class MyBidsTableViewCell: UITableViewCell {
override func setSelected(selected: Bool, animated: Bool) {
let originColor = label.backgroundColor
super.setSelected(selected, animated: animated)
label.backgroundColor = originColor
}
override func setHighlighted(highlighted: Bool, animated: Bool) {
let originColor = label.backgroundColor
super.setHighlighted(highlighted, animated: animated)
label.backgroundColor = originColor
}
}