美文网首页
点击cell时有背景颜色的控件点击后会闪下

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

作者: 老街灯塔 | 来源:发表于2017-12-25 17:55 被阅读154次

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

}

}

相关文章

网友评论

      本文标题:点击cell时有背景颜色的控件点击后会闪下

      本文链接:https://www.haomeiwen.com/subject/gntrgxtx.html