Skip to content

iOS Blinking/Flashing label

Platform License

extension UILabel {
    //MARK: StartBlink
    func startBlink() {
        UIView.animate(withDuration: 0.8,//Time duration
                    delay:0.0,
                    options:[.allowUserInteraction, .curveEaseInOut, .autoreverse, .repeat], 
                    animations: { self.alpha = 0 }, completion: nil)
    }

    //MARK: StopBlink
    func stopBlink() {
        layer.removeAllAnimations()
        alpha = 1
    }
}
yourLabelName.alpha = 1.0f;// yourLabelName
[UIView animateWithDuration:0.8 delay:0.0 options: UIViewAnimationOptionCurveEaseInOut |                                                            UIViewAnimationOptionRepeat |
                                                UIViewAnimationOptionAutoreverse |
                                                UIViewAnimationOptionAllowUserInteraction
                                        animations:^{
                                            yourLabelName.alpha = 0.0f;// yourLabelName
                                        }
                                        completion:^(BOOL finished){
                                            // Do nothing
                                        }];

You can change the values to get different effects.

For example:

Tip

Changing animateWithDuration will set the blinking speed, repeat will give you continuous blinking effects.

Further you can use it on anything that inherits from UIView example a UIButton, UILabel, custom view, etc.

Sample