Animate a color or text change in UILabel with swift, my extension.
extension UILabel {
public func setTextAnimation(text: String? = nil, color: UIColor? = nil, duration: NSTimeInterval?, completion:(()->())? = nil) {
UIView.transitionWithView(self, duration: duration ?? 0.3, options: .TransitionCrossDissolve, animations: { () -> Void in
self.text = text ?? self.text
self.textColor = color ?? self.textColor
}) { (finish) in
if finish { completion?() }
}
}
}
Use for color:
self.label.setTextAnimation(color: UIColor.whiteColor(), duration: 0.15)
source
share