Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fading in and out UIButton in view

Tags:

ios

ipad

uibutton

In my iPad app I need to display cover-Images of publications. The user can tap on a cover to get details.

I thought about rendering UIButtons as custom buttons with the cover image as Background-image. Is it possible to fade UIButtons in and out? The user can choose a category of publications to be displayed, and ih he changes the category I wanted to fade some publications out.

like image 291
MadMaxAPP Avatar asked Nov 08 '11 08:11

MadMaxAPP


2 Answers

The alpha property of any UIView (which includes a UIButton) can be animated using the block-based animations method:

[UIView animateWithDuration:0.25 animations:^{myButton.alpha = 0.0;}];

This will fade your button out over a 0.25 second period. Set the alpha to 1.0 to fade it back in again.

like image 104
jrturton Avatar answered Nov 20 '22 15:11

jrturton


If you want the button to respond to events while it's animating, make sure to enable user interaction

[UIView
        animateWithDuration:5.0
        delay:0.0
        options:UIViewAnimationOptionAllowUserInteraction
        animations:^{ button.alpha = 0.0; }
        completion:nil];
like image 44
Justas Avatar answered Nov 20 '22 15:11

Justas