Reputation: 4906
I'm trying to write a function for animate a UIButton doing the following points in order:
So I write this:
static func pulseTitleLabel(button: UIButton, text: String, color: UIColor)
{
button.setTitle(text, forState: [.Normal, .Highlighted])
button.setTitleColor(color, forState: [.Normal, .Highlighted])
UIView.animateWithDuration(1.0, delay: 0.0, options: [.Repeat, .Autoreverse], animations: { () -> Void in
button.titleLabel?.alpha = 0.0
}, completion: nil)
}
but I can't see any animation.
The title button becomes with the text and the color that I want but the animation doesn't start: I'm missing something? There's another better and elegant way to do the same points?
Upvotes: 0
Views: 600
Reputation: 1017
I tried you code an it didn't work for me because I used System Button. I changed the type of the button to Custom and it works now (I see pulse animation if it's expected). Can you verify that the type of the button is custom?
In general, your approach is good enough. If you'd like to research more complex animations (not only for buttons), take a look at Facebook Pop animations https://github.com/facebook/pop (some examples https://github.com/hossamghareeb/Facebook-POP-Tutorial)
Upvotes: 2