借鉴相关资料,整理了一个很有意思的button动画效果,iOS自定义UIButton点击动画特效
先看一下效果图:
下面贴上代码:
ViewController:
#import
@interface ViewController : UIViewController
@end
#import "ViewController.h"
#import "HWButton.h"
#define mainW [UIScreen mainScreen].bounds.size.width
#define mainH [UIScreen mainScreen].bounds.size.height
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
//创建控件
[self creatButton];
}
- (void)creatButton
{
HWButton *button = [[HWButton alloc] initWithFrame:CGRectMake(mainW * 0.5 - 60, mainH - 100, 120, 72) maxLeft:100 maxRight:100 maxHeight:300];
[button setImage:[UIImage imageNamed:@"button"] forState:UIControlStateNormal];
button.images = @[[UIImage imageNamed:@"Circle 1"], [UIImage imageNamed:@"Circle 2"], [UIImage imageNamed:@"Circle 3"], [UIImage imageNamed:@"Hero"]];
button.duration = 10;
[button addTarget:self action:@selector(buttonOnClick:) forControlEvents:UIControlEventTouchUpInsid