How to make a button flash or blink?

前端 未结 12 1058
不思量自难忘°
不思量自难忘° 2021-02-01 06:17

I am trying to change a button\'s color (just a flash/blink) to green when a scan is correct and red when there\'s a problem. I am able to do this with a view like so

         


        
12条回答
  •  逝去的感伤
    2021-02-01 07:12

    Swift 3.0

    func btnFlash_Clicked(sender: AnyObject) {
    
        if !flashing{
            callButton.alpha = 1.0
            UIView.animate(withDuration: 0.5, delay: 0.0, options: [.allowUserInteraction], animations: {() -> Void in
                callButton.alpha = 0.5
            }, completion: {(finished: Bool) -> Void in
            })
    
            flashing = true
        }
        else{
            flashing = false
            callButton.alpha = 0.5
            UIView.animate(withDuration: 0.5, delay: 0.0, options: [.allowUserInteraction], animations: {() -> Void in
                callButton.alpha = 1.0
            }, completion: {(finished: Bool) -> Void in
            })
        }
    }
    

提交回复
热议问题