EDIT: I would actually like to animate the textColor
property. I thought it would be the same solution as for backgroundColor
but apparently not because textColor
is not available in layer
. I found the solution to this here.
I'm trying to change the color of the background of a UILabel
randomly every one second. The code I am using works fine on a regular view, but is iterating way too fast when I call it on the label. Its as though animate with duration is not taking any time on the label. Any idea why this is? I actually would like to change the label text color so that's why its important it works on the label.
colorChanges(v: lbl) // TOO FAST!
colorChanges(v: someView) // PERFECT
colorChanges(v: self.view) // PERFECT
Animation Code
func colorChanges(v: UIView) {
UIView.animate(withDuration: 1.0, animations: {
v.backgroundColor = UIColor(displayP3Red: CGFloat(arc4random()) / CGFloat(UInt32.max), green: CGFloat(arc4random()) / CGFloat(UInt32.max), blue: CGFloat(arc4random()) / CGFloat(UInt32.max), alpha: 1.0)
}, completion: {
(value: Bool) in
self.colorChanges(v: v)
})
}
Weird Behavior