【发布时间】:2018-08-20 04:11:15
【问题描述】:
当UITableViewCell被选中时,有很多例子可以改变UILabel文本的颜色。但所有示例都用以下几行解释
if cell.selected {
cell.txtLabel1.textColor = UIColor.redColor()
}else {
cell.txtLabel1.textColor = UIColor.blackColor()
}
但是设置 cell.txtLabel1.highlightedTextColor = UIColor.redColor() 非常简单。粗体线会导致任何问题吗?为什么其他示例没有粗体线实现?
如果不设置 isHighlighted 为 UILabel 也会在选择 UITableViewCell 时改变文本的颜色。代码贴在下面供参考
class MenuViewCell: UITableViewCell {
@IBOutlet weak var lblTitle:UILabel?
@IBOutlet weak var imgIcon:UIImageView?
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
let selectedView = UIView()
selectedView.backgroundColor = UIColor(colorLiteralRed: 244.0/255.0, green: 244.0/255.0, blue: 245.0/255.0, alpha: 1)
selectedBackgroundView = selectedView
lblTitle?.highlightedTextColor = UIColor(colorLiteralRed: 224.0/255.0, green: 121.0/255.0, blue: 43.0/255.0, alpha: 1)
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
【问题讨论】:
标签: ios iphone swift uitableview uilabel