[英]Can't set textColor of UILabel
我目前正在处理源自UITableViewCells Xibs的动态表单。
if disabled {
self.passTitleLabel.textColor = UIColor(named: "Dark Blue")
self.textField.textColor = UIColor(named: "Dark Blue")
} else {
self.passTitleLabel.textColor = UIColor(named: "Light Blue")
self.textField.textColor = .white
}
UILabel( passTitleLabel
)保留在Storyboard文件上设置的颜色,并且不会按预期更改。 UILabel已启用且未突出显示,但仍保留情节提要板上的颜色。
所有颜色都在其他类中起作用(它们位于Assets.xcassets
)。 标签已通过IBOutlet正确设置。
遇到同样的问题,花了我一段时间,但终于找到了答案。 看起来您的UITableViewCell或UICollectionViewCell在后台线程中运行,与UI相关的操作需要在主线程中完成,否则可能导致这些类型的问题。
if disabled {
DispatchQueue.main.async {
self.passTitleLabel.textColor = UIColor(named: "Dark Blue")
self.textField.textColor = UIColor(named: "Dark Blue")
}
} else {
DispatchQueue.main.async {
self.passTitleLabel.textColor = UIColor(named: "Light Blue")
self.textField.textColor = .white
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.