Here is what I did (inside a subclass of UIButton):
Set the button images as usual:
[self setBackgroundImage:[[UIImage imageNamed:@"button"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)] forState:UIControlStateNormal]; [self setBackgroundImage:[[UIImage imageNamed:@"button_pressed"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)] forState:UIControlStateHighlighted];
Override selection:
- (void)setHighlighted:(BOOL)highlighted { [UIView transitionWithView:self duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowAnimatedContent animations:^{ [super setHighlighted:highlighted]; } completion:nil]; }
kgaidis
source share