[Swift] set UILabel fade-in fade-out continuity

January 08, 2017 0 Comments

extension UILabel {
    /**
     Set Text With animation fadein fadeout
     - parameter duration: NSTimeInterval?
     */
    public func setTextAnimation(duration: TimeInterval?, completion:(()->())? = nil) {
        UIView.animate(withDuration: duration!, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: {
            self.alpha = 0.0
        }, completion: {
            (finished: Bool) -> Void in
            // Fade in
            UIView.animate(withDuration: duration!, delay: 0.0, options: UIViewAnimationOptions.curveEaseIn, animations: {
                self.alpha = 1.0
            }, completion: {
                (finished: Bool) -> Void in
                self.setTextAnimation(duration: duration!)
            })
        })
    }

}

0 comments: