Rivera Rivera - 3 months ago 34
iOS Question

Prevent UIButton's setTitle:forState: animation

I am using a

NSTimer
to update a
UIButton
's title every second.

It works but the text in the title blinks (animates to alpha
0
and back) automatically.

I tried to use
button.layer.removeAllAnimations()
with no luck, and no exceptions, so QuartzCore seems to be correctly linked.




Current non-working paranoid code:

UIView.setAnimationsEnabled(false)
UIView.performWithoutAnimation {
button.setTitle(time, forState: .Normal)
button.layer.removeAllAnimations()
}
UIView.setAnimationsEnabled(true)

Answer

Make sure your button is a "custom" button and not a "system" button.

If you created it on a storyboard, then just change the Button Type. If you created it programmatically, then it should be:

UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
Comments