6

What i want to do is, when the user clicks the button then the button should fill with color with animation from bottom to top.

I tried this which added the color but the animation effect was not added.

float originalY = btn.frame.origin.y;
float originalH = btn.bounds.size.height;

[UIView animateWithDuration:3.0f
                      delay:1.0f
                    options:UIViewAnimationOptionTransitionFlipFromBottom
                 animations:^{

    btn.frame = CGRectMake(btn.frame.origin.x, (originalY + originalH), btn.bounds.size.width, 0);
    [btn setBackgroundImage:[UIImage imageNamed:@"Screen Shot 2012-11-07 at 4.22.30 PM.png"] forState:UIControlStateNormal];
    [btn setTitleColor:[[UIColor alloc]initWithRed:38.0/255.0 green:38.0/255.0 blue:38.0/255.0 alpha:1.0] forState:UIControlStateNormal];
} completion:^(BOOL finished) {
}];
iDev
  • 23,310
  • 7
  • 60
  • 85
Prashant Chaudhari
  • 1,239
  • 1
  • 9
  • 18

2 Answers2

-1

The best solution would be to subclass UIButton and add a method that changes the background image's alpha value from 0 to 1.

Or you could just override the drawRect method and fill up the background with a color there.

MweyaMutsvene
  • 543
  • 4
  • 15
-2

i think you probably do something like this, i used UIlabel it may also work for UIButton to .

#import <QuartzCore/QuartzCore.h>

....

'theLabel.layer.backgroundColor = [UIColor whiteColor].CGColor;

[UIView animateWithDuration:2.0 animations:^{ theLabel.layer.backgroundColor = [UIColor greenColor].CGColor; } completion:NULL];'`

bLacK hoLE
  • 781
  • 1
  • 7
  • 20
  • That is not going to change color bottom to top - it may however change to color of the whole button but I don't think this is the question... – Moonwalker Aug 12 '14 at 10:48
  • increase the time in animateWithDuration: and it will show the effect thanks. – bLacK hoLE Aug 12 '14 at 10:51