Helosy
Helosy

Reputation: 359

Fading in/out a UILabel

My stackview contains 2 labels. I want to animate the hiding process like giving it a fade out animation when one of the labels is hidden or a fade in animation when one of the labels is unhidden. How would I do this?

Upvotes: 3

Views: 1676

Answers (2)

Rakesha Shastri
Rakesha Shastri

Reputation: 11242

You should animate the alpha of the label.

UIView.animate(withDuration: 1, animations: {
    disclaimerLabel.alpha = 0
}

Upvotes: 3

Vinay
Vinay

Reputation: 9

    let flash = CABasicAnimation(keyPath: "opacity")
    flash.duration = 0.5
    flash.fromValue = 1
    flash.toValue = 0.1
    flash.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    flash.autoreverses = true
    flash.repeatCount = 3

    la1.layer.add(flash, forKey: nil)

Upvotes: -1

Related Questions