Skip to content

Commit 2db08aa

Browse files
committed
- Adds titleAlpha + imageAlpha state customizations
- Update example project with... examples
1 parent aabff39 commit 2db08aa

7 files changed

Lines changed: 234 additions & 40 deletions

File tree

Example/AXStateButtonExample/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "20x20",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "20x20",
11+
"scale" : "3x"
12+
},
313
{
414
"idiom" : "iphone",
515
"size" : "29x29",
@@ -30,6 +40,16 @@
3040
"size" : "60x60",
3141
"scale" : "3x"
3242
},
43+
{
44+
"idiom" : "ipad",
45+
"size" : "20x20",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"size" : "20x20",
51+
"scale" : "2x"
52+
},
3353
{
3454
"idiom" : "ipad",
3555
"size" : "29x29",
@@ -59,6 +79,11 @@
5979
"idiom" : "ipad",
6080
"size" : "76x76",
6181
"scale" : "2x"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"size" : "83.5x83.5",
86+
"scale" : "2x"
6287
}
6388
],
6489
"info" : {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "layers.pdf"
6+
}
7+
],
8+
"info" : {
9+
"version" : 1,
10+
"author" : "xcode"
11+
},
12+
"properties" : {
13+
"template-rendering-intent" : "template"
14+
}
15+
}
Binary file not shown.

Example/AXStateButtonExample/ViewController.m

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,34 @@ - (void)viewDidLoad {
3939

4040
- (AXStateButton *)createMaterialButton {
4141
AXStateButton *button = [AXStateButton button];
42-
button.controlStateAnimationDuration = 0.1;
4342
[button addTarget:self action:@selector(buttonTap:) forControlEvents:UIControlEventTouchUpInside];
4443

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)];
44+
[button setImage:[UIImage imageNamed:@"layers"] forState:UIControlStateNormal];
45+
[button setTintColor:[UIColor whiteColor] forState:UIControlStateNormal];
46+
[button setTintColor:[UIColor cyanColor] forState:UIControlStateSelected];
47+
[button setTintColor:[UIColor cyanColor] forState:UIControlStateHighlighted | UIControlStateSelected];
48+
[button setImageAlpha:1.0 forState:UIControlStateNormal];
49+
[button setImageAlpha:0.8 forState:UIControlStateHighlighted];
50+
[button setImageAlpha:0.8 forState:UIControlStateHighlighted | UIControlStateSelected];
5251

5352
[button setTransformRotationZ:0 forState:UIControlStateNormal];
5453
// [button setTransformRotationZ:M_PI_4 forState:UIControlStateHighlighted];
5554

5655
[button setTransformScale:1.0 forState:UIControlStateNormal];
57-
[button setTransformScale:0.95 forState:UIControlStateHighlighted];
56+
// [button setTransformScale:0.95 forState:UIControlStateHighlighted];
57+
// [button setTransformScale:0.95 forState:UIControlStateHighlighted | UIControlStateSelected];
5858

5959
[button setShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
60-
[button setShadowOpacity:0.2 forState:UIControlStateNormal];
6160
[button setShadowOffset:CGSizeMake(2, 2) forState:UIControlStateNormal];
61+
[button setShadowOpacity:0.2 forState:UIControlStateNormal];
6262
[button setShadowOpacity:0.4 forState:UIControlStateHighlighted];
63+
[button setShadowOpacity:0.4 forState:UIControlStateHighlighted | UIControlStateSelected];
6364

6465
[button setBackgroundColor:[UIColor redColor] forState:UIControlStateNormal];
6566
[button setBackgroundColor:[UIColor colorWithRed:216. / 255. green:0.0 blue:0.0 alpha:1.0]
6667
forState:UIControlStateHighlighted];
68+
[button setBackgroundColor:[UIColor colorWithRed:216. / 255. green:0.0 blue:0.0 alpha:1.0]
69+
forState:UIControlStateHighlighted | UIControlStateSelected];
6770

6871
CGSize buttonSize = CGSizeMake(56, 56);
6972
[button setCornerRadius:buttonSize.height / 2 forState:UIControlStateNormal];
@@ -114,6 +117,9 @@ - (AXStateButton *)createLoadingButton {
114117
}]
115118
forState:UIControlStateDisabled];
116119

120+
[button setTitleAlpha:1.0 forState:UIControlStateNormal];
121+
[button setTitleAlpha:0.8 forState:UIControlStateHighlighted];
122+
117123
[button setShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
118124
[button setShadowOpacity:0.2 forState:UIControlStateNormal];
119125
[button setShadowOffset:CGSizeMake(2, 2) forState:UIControlStateNormal];

Source/AXStateButton.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,38 @@ NS_SWIFT_NAME(StateButton)
6363
*/
6464
- (void)setAlpha:(CGFloat)alpha forState:(UIControlState)controlState;
6565

66+
/**
67+
Change the button title's alpha based on its state.
68+
69+
@param alpha The desired alpha.
70+
@param controlState The button's control state.
71+
*/
72+
- (void)setTitleAlpha:(CGFloat)alpha forState:(UIControlState)controlState;
73+
74+
/**
75+
Retrieve the button title's alpha for a state.
76+
77+
@param controlState The button's control state.
78+
@return The button title's alpha.
79+
*/
80+
- (CGFloat)titleAlphaForState:(UIControlState)controlState;
81+
82+
/**
83+
Change the button image's alpha based on its state.
84+
85+
@param alpha The desired alpha.
86+
@param controlState The button's control state.
87+
*/
88+
- (void)setImageAlpha:(CGFloat)alpha forState:(UIControlState)controlState;
89+
90+
/**
91+
Retrieve the button image's alpha for a state.
92+
93+
@param controlState The button's control state.
94+
@return The button image's alpha.
95+
*/
96+
- (CGFloat)imageAlphaForState:(UIControlState)controlState;
97+
6698
/**
6799
Retrieve the button's alpha for a state.
68100

0 commit comments

Comments
 (0)