How to animate a UIButton selected background Image
Posted
by Thomas Joos
on Stack Overflow
See other posts from Stack Overflow
or by Thomas Joos
Published on 2010-06-15T10:00:18Z
Indexed on
2010/06/15
10:02 UTC
Read the original article
Hit count: 240
hi all,
I have a class defining a custom UIButton. I configurate a normal and selected state like this:
//custom image
UIImage *image = [UIImage imageNamed:@"customIconCreationBG.png"];
UIImage *stretchImage = [image stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0];
[self setBackgroundImage:stretchImage forState:UIControlStateNormal];
UIImage *imageSelected = [UIImage imageNamed:@"customIconCreationBG_selected.png"];
UIImage *stretchImageSelected = [imageSelected stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0];
[self setBackgroundImage:stretchImageSelected forState:UIControlStateSelected];
In another class I'm filling an array with custom buttons and i'm adding a button pressed method. It sets the selected state to TRUE
-(void)buttnPressed:(id)sender { NSLog(@"button pressed");
[[NSNotificationCenter defaultCenter] postNotificationName:@"unselectBGIcons" object:self];
HorizontalListIcon *pressedIcon = ((HorizontalListIcon *)sender);
[pressedIcon setSelected:TRUE];
}
The button switches to another background, which is great. Is there a way to animate this change ( fading in? ) because it's a bit hard now.
Greets
© Stack Overflow or respective owner