点击cell时有背景颜色的控件点击后会闪下

问题描述:原来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

}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容