Reputation: 31
I'm currently working on a dynamic form that's originated from 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
}
The UILabel (passTitleLabel
) keeps the color set on the Storyboard file and doesn't change as expected. The UILabel is enabled and not highlighted but it is still preserving the color on the storyboard.
All the colors are working in other classes (they're on Assets.xcassets
). The Label is properly set with an IBOutlet.
Upvotes: 3
Views: 1982
Reputation: 91
Ran into the same issue, took me a while but finally found an answer. Looks like your UITableViewCell or UICollectionViewCell is running in a background thread, UI related operations need to be done in the main thread or it can lead to these type of problems.
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
}
}
Upvotes: 9