Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Fade in UIButton

how can I fade in a UIButton in a view?

now I add it with:

    [myView addSubview:myButton];

but if I want to fade it?

[UIView animateWithDuration:3.0
delay:0.0
options: UIViewAnimationCurveEaseInOut
animations:^{myButton.alpha = 1.0}
completion:^(BOOL finished){ [myView addSubview:myButton]; }];

Thanks!

like image 633
Andref Avatar asked Dec 27 '22 19:12

Andref


1 Answers

Try using

myButton.alpha = 0.0;
[myView addSubview:myButton];

prior to the animation call.

[UIView animateWithDuration:3.0
                      delay:0.0
                    options: UIViewAnimationCurveEaseInOut
                 animations:^{myButton.alpha = 1.0;}
                 completion:nil];

If you fade it in and add to view, the fading in part will not be within the bounds of the view (will be offscreen). So add it first at zero alpha and then fade it in.

like image 177
Deepak Danduprolu Avatar answered Dec 31 '22 13:12

Deepak Danduprolu