Ios Can';设置UILabel的文本颜色
我目前正在开发一个源自UITableViewCells Xibs的动态表单Ios Can';设置UILabel的文本颜色,ios,swift,uilabel,uicolor,Ios,Swift,Uilabel,Uicolor,我目前正在开发一个源自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")
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(PasstTitleLabel
)保留故事板文件上设置的颜色,不会按预期更改。UILabel已启用且未高亮显示,但仍保留故事板上的颜色
所有颜色都在其他类中工作(它们位于
Assets.xcsets
)。标签正确地设置了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
}
}
你发布的代码在哪里?将行拆分为2行。例如,
let color=UIColor(名为:“深蓝色”)
然后self.passTitleLabel.textColor=color
。确保运行时color
不是nil
。@rmaddy在调用单元格更新时调用代码,就像表单的其他字段一样。我确实分成了两行,还是一样。谢谢:)我猜,passTitleLabel
插座连接到的标签与您想象的不同。当您拆分这些行时,color
nil与否?