1212@interface ViewController ()
1313
1414@property AXStateButton *materialButton;
15+ @property AXStateButton *tryAgainButton;
1516@property AXStateButton *loadingButton;
1617
1718@end
@@ -27,100 +28,131 @@ - (void)viewDidLoad {
2728 self.materialButton = [self createMaterialButton ];
2829 [self .view addSubview: self .materialButton];
2930
31+ // Try again button
32+ self.tryAgainButton = [self createTryAgainButton ];
33+ [self .view addSubview: self .tryAgainButton];
34+
3035 // Sample loading button
3136 self.loadingButton = [self createLoadingButton ];
3237 [self .view addSubview: self .loadingButton];
3338}
3439
3540- (AXStateButton *)createMaterialButton {
36- AXStateButton *materialButton = [AXStateButton button ];
37- materialButton .controlStateAnimationDuration = 0.1 ;
38- [materialButton addTarget: self action: @selector (buttonTap: ) forControlEvents: UIControlEventTouchUpInside];
41+ AXStateButton *button = [AXStateButton button ];
42+ button .controlStateAnimationDuration = 0.1 ;
43+ [button addTarget: self action: @selector (buttonTap: ) forControlEvents: UIControlEventTouchUpInside];
3944
40- [materialButton setAttributedTitle: [[NSAttributedString alloc ] initWithString: @" +"
41- attributes: @{
42- NSFontAttributeName : [UIFont boldSystemFontOfSize: 28 ],
43- NSForegroundColorAttributeName : [UIColor whiteColor ]
44- }]
45- forState: UIControlStateNormal];
46- [materialButton setTitleEdgeInsets: UIEdgeInsetsMake (0 , 0 , 4 , 0 )];
45+ [button setAttributedTitle: [[NSAttributedString alloc ] initWithString: @" +"
46+ attributes: @{
47+ NSFontAttributeName : [UIFont boldSystemFontOfSize: 28 ],
48+ NSForegroundColorAttributeName : [UIColor whiteColor ]
49+ }]
50+ forState: UIControlStateNormal];
51+ [button setTitleEdgeInsets: UIEdgeInsetsMake (0 , 0 , 4 , 0 )];
4752
48- [materialButton setTransformRotationZ: 0 forState: UIControlStateNormal];
49- // [materialButton setTransformRotationZ:M_PI_4 forState:UIControlStateHighlighted];
53+ [button setTransformRotationZ: 0 forState: UIControlStateNormal];
54+ // [button setTransformRotationZ:M_PI_4 forState:UIControlStateHighlighted];
5055
51- [materialButton setTransformScale: 1.0 forState: UIControlStateNormal];
52- [materialButton setTransformScale: 0.95 forState: UIControlStateHighlighted];
56+ [button setTransformScale: 1.0 forState: UIControlStateNormal];
57+ [button setTransformScale: 0.95 forState: UIControlStateHighlighted];
5358
54- [materialButton setShadowColor: [UIColor blackColor ] forState: UIControlStateNormal];
55- [materialButton setShadowOpacity: 0.2 forState: UIControlStateNormal];
56- [materialButton setShadowOffset: CGSizeMake (2 , 2 ) forState: UIControlStateNormal];
57- [materialButton setShadowOpacity: 0.4 forState: UIControlStateHighlighted];
59+ [button setShadowColor: [UIColor blackColor ] forState: UIControlStateNormal];
60+ [button setShadowOpacity: 0.2 forState: UIControlStateNormal];
61+ [button setShadowOffset: CGSizeMake (2 , 2 ) forState: UIControlStateNormal];
62+ [button setShadowOpacity: 0.4 forState: UIControlStateHighlighted];
5863
59- [materialButton setBackgroundColor: [UIColor redColor ] forState: UIControlStateNormal];
60- [materialButton setBackgroundColor: [UIColor colorWithRed: 216 . / 255 . green: 0.0 blue: 0.0 alpha: 1.0 ]
61- forState: UIControlStateHighlighted];
64+ [button setBackgroundColor: [UIColor redColor ] forState: UIControlStateNormal];
65+ [button setBackgroundColor: [UIColor colorWithRed: 216 . / 255 . green: 0.0 blue: 0.0 alpha: 1.0 ]
66+ forState: UIControlStateHighlighted];
6267
6368 CGSize buttonSize = CGSizeMake (56 , 56 );
64- [materialButton setCornerRadius: buttonSize.height / 2 forState: UIControlStateNormal];
65- materialButton .frame = (CGRect){ CGPointZero, buttonSize };
69+ [button setCornerRadius: buttonSize.height / 2 forState: UIControlStateNormal];
70+ button .frame = (CGRect){ CGPointZero, buttonSize };
6671
67- return materialButton;
72+ return button;
73+ }
74+
75+ - (AXStateButton *)createTryAgainButton {
76+ AXStateButton *button = [AXStateButton button ];
77+ // [button addTarget:self action:@selector(buttonTap:) forControlEvents:UIControlEventTouchUpInside];
78+
79+ [button setTitle: @" Try again" forState: UIControlStateNormal];
80+ [button setTitleColor: [UIColor lightGrayColor ] forState: UIControlStateNormal];
81+
82+ [button setAlpha: 1.0 forState: UIControlStateNormal];
83+ [button setAlpha: 0.7 forState: UIControlStateHighlighted];
84+
85+ [button setTransformScale: 1.0 forState: UIControlStateNormal];
86+ [button setTransformScale: 0.95 forState: UIControlStateHighlighted];
87+
88+ [button setBorderWidth: 1.0 forState: UIControlStateNormal];
89+ [button setBorderColor: [UIColor lightGrayColor ] forState: UIControlStateNormal];
90+
91+ [button setBackgroundColor: [UIColor clearColor ] forState: UIControlStateNormal];
92+
93+ CGSize buttonSize = CGSizeMake (90 , 30 );
94+ [button setCornerRadius: 6.0 forState: UIControlStateNormal];
95+ button.frame = (CGRect){ CGPointZero, buttonSize };
96+
97+ return button;
6898}
6999
70100- (AXStateButton *)createLoadingButton {
71- AXStateButton *loadingButton = [AXStateButton button ];
72- loadingButton.controlStateAnimationDuration = 0.1 ;
73- [loadingButton addTarget: self action: @selector (buttonTap: ) forControlEvents: UIControlEventTouchUpInside];
74-
75- [loadingButton setAttributedTitle: [[NSAttributedString alloc ] initWithString: @" Load"
76- attributes: @{
77- NSFontAttributeName : [UIFont boldSystemFontOfSize: 17 ],
78- NSForegroundColorAttributeName : [UIColor whiteColor ]
79- }]
80- forState: UIControlStateNormal];
81- [loadingButton setAttributedTitle: [[NSAttributedString alloc ] initWithString: @" Loading..."
82- attributes: @{
83- NSFontAttributeName : [UIFont boldSystemFontOfSize: 17 ],
84- NSForegroundColorAttributeName : [UIColor whiteColor ]
85- }]
86- forState: UIControlStateDisabled];
87-
88- [loadingButton setShadowColor: [UIColor blackColor ] forState: UIControlStateNormal];
89- [loadingButton setShadowOpacity: 0.2 forState: UIControlStateNormal];
90- [loadingButton setShadowOffset: CGSizeMake (2 , 2 ) forState: UIControlStateNormal];
91- [loadingButton setShadowOpacity: 0.4 forState: UIControlStateHighlighted];
92-
93- [loadingButton setTransformRotationX: 0 forState: UIControlStateNormal];
94- [loadingButton setTransformRotationX: M_PI forState: UIControlStateDisabled];
95-
96- [loadingButton setTransformRotationY: 0 forState: UIControlStateNormal];
97- [loadingButton setTransformRotationY: M_PI forState: UIControlStateDisabled];
98-
99- [loadingButton setTransformRotationZ: 0 forState: UIControlStateNormal];
100- [loadingButton setTransformRotationZ: M_PI forState: UIControlStateDisabled];
101-
102- [loadingButton setBackgroundColor: [UIColor purpleColor ] forState: UIControlStateNormal];
103- [loadingButton setBackgroundColor: [UIColor colorWithRed: 102 . / 255 . green: 0.0 blue: 102 . / 255 . alpha: 1.0 ]
104- forState: UIControlStateHighlighted];
105- [loadingButton setBackgroundColor: [UIColor grayColor ] forState: UIControlStateDisabled];
101+ AXStateButton *button = [AXStateButton button ];
102+ [button addTarget: self action: @selector (buttonTap: ) forControlEvents: UIControlEventTouchUpInside];
103+
104+ [button setAttributedTitle: [[NSAttributedString alloc ] initWithString: @" Load"
105+ attributes: @{
106+ NSFontAttributeName : [UIFont boldSystemFontOfSize: 17 ],
107+ NSForegroundColorAttributeName : [UIColor whiteColor ]
108+ }]
109+ forState: UIControlStateNormal];
110+ [button setAttributedTitle: [[NSAttributedString alloc ] initWithString: @" Loading..."
111+ attributes: @{
112+ NSFontAttributeName : [UIFont boldSystemFontOfSize: 17 ],
113+ NSForegroundColorAttributeName : [UIColor whiteColor ]
114+ }]
115+ forState: UIControlStateDisabled];
116+
117+ [button setShadowColor: [UIColor blackColor ] forState: UIControlStateNormal];
118+ [button setShadowOpacity: 0.2 forState: UIControlStateNormal];
119+ [button setShadowOffset: CGSizeMake (2 , 2 ) forState: UIControlStateNormal];
120+ [button setShadowOpacity: 0.4 forState: UIControlStateHighlighted];
121+
122+ [button setTransformRotationX: 0 forState: UIControlStateNormal];
123+ [button setTransformRotationX: M_PI forState: UIControlStateDisabled];
124+
125+ [button setTransformRotationY: 0 forState: UIControlStateNormal];
126+ [button setTransformRotationY: M_PI forState: UIControlStateDisabled];
127+
128+ [button setTransformRotationZ: 0 forState: UIControlStateNormal];
129+ [button setTransformRotationZ: M_PI forState: UIControlStateDisabled];
130+
131+ [button setBackgroundColor: [UIColor purpleColor ] forState: UIControlStateNormal];
132+ [button setBackgroundColor: [UIColor colorWithRed: 102 . / 255 . green: 0.0 blue: 102 . / 255 . alpha: 1.0 ]
133+ forState: UIControlStateHighlighted];
134+ [button setBackgroundColor: [UIColor grayColor ] forState: UIControlStateDisabled];
106135
107136 CGSize buttonSize = CGSizeMake (100 , 50 );
108- [loadingButton setCornerRadius: buttonSize.height / 2 forState: UIControlStateNormal];
109- [loadingButton setCornerRadius: 0 forState: UIControlStateDisabled];
110- loadingButton .frame = (CGRect){ CGPointZero, buttonSize };
137+ [button setCornerRadius: buttonSize.height / 2 forState: UIControlStateNormal];
138+ [button setCornerRadius: 0 forState: UIControlStateDisabled];
139+ button .frame = (CGRect){ CGPointZero, buttonSize };
111140
112- return loadingButton ;
141+ return button ;
113142}
114143
115144- (void )viewWillLayoutSubviews {
116145 [super viewWillLayoutSubviews ];
117146
118147 CGPoint materialButtonCenter = self.view .center ;
119- materialButtonCenter.y -= 50 ;
148+ materialButtonCenter.y -= 100 ;
120149 self.materialButton .center = materialButtonCenter;
121150
151+ CGPoint tryAgainButtonCenter = self.view .center ;
152+ self.tryAgainButton .center = tryAgainButtonCenter;
153+
122154 CGPoint loadingButtonCenter = self.view .center ;
123- loadingButtonCenter.y += 50 ;
155+ loadingButtonCenter.y += 100 ;
124156 self.loadingButton .center = loadingButtonCenter;
125157}
126158
0 commit comments