Skip to content

Instantly share code, notes, and snippets.

@edwardean
Created January 9, 2017 07:18
Show Gist options
  • Save edwardean/ec0e140d2c723117d4a1a7d5aa9f5717 to your computer and use it in GitHub Desktop.
Save edwardean/ec0e140d2c723117d4a1a7d5aa9f5717 to your computer and use it in GitHub Desktop.
UILabel text animation
let label = UILabel()
label.frame = CGRect(x: 0.0, y: 0.0, width: 400.0, height: 75.0)
label.backgroundColor = UIColor.whiteColor()
label.font = UIFont.preferredFontForTextStyle(UIFontTextStyleTitle1)
label.textAlignment = .Center
label.text = "Hello, world!"
let fadeTransition = CATransition()
fadeTransition.duration = 0.2
CATransaction.begin()
CATransaction.setCompletionBlock({
label.text = "Goodnight, moon..."
label.layer.addAnimation(fadeTransition, forKey: kCATransition)
})
label.text = ""
label.layer.addAnimation(fadeTransition, forKey: kCATransition)
CATransaction.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment