@@ -14,76 +14,76 @@ @implementation UIBarButtonItem (FlatUI)
14
14
- (void ) configureFlatButtonWithColor : (UIColor *)color
15
15
highlightedColor : (UIColor *)highlightedColor
16
16
cornerRadius : (CGFloat) cornerRadius {
17
-
18
- [UIBarButtonItem configureItemOrProxy: self forFlatButtonWithColor: color highlightedColor: color cornerRadius: cornerRadius];
19
-
17
+
18
+ [UIBarButtonItem configureItemOrProxy: self forFlatButtonWithColor: color highlightedColor: highlightedColor cornerRadius: cornerRadius];
19
+
20
20
}
21
21
22
22
+ (void ) configureFlatButtonsWithColor : (UIColor *) color
23
23
highlightedColor : (UIColor *)highlightedColor
24
24
cornerRadius : (CGFloat) cornerRadius {
25
-
26
- [self configureFlatButtonsWithColor: color highlightedColor: highlightedColor cornerRadius: cornerRadius whenContainedIn: [UINavigationBar class ], [UINavigationController class ], nil ];
25
+
26
+ [self configureFlatButtonsWithColor: color highlightedColor: highlightedColor cornerRadius: cornerRadius whenContainedIn: [UINavigationBar class ], [UINavigationController class ], nil ];
27
27
}
28
28
29
29
+ (void ) configureFlatButtonsWithColor : (UIColor *) color
30
30
highlightedColor : (UIColor *)highlightedColor
31
31
cornerRadius : (CGFloat) cornerRadius
32
32
whenContainedIn : (Class <UIAppearanceContainer>)containerClass , ... {
33
- va_list vl;
34
- va_start (vl, containerClass);
35
- id appearance = [UIBarButtonItem appearanceWhenContainedIn: containerClass, nil ];
36
- va_end (vl);
37
- [UIBarButtonItem configureItemOrProxy: appearance forFlatButtonWithColor: color highlightedColor: color cornerRadius: cornerRadius];
33
+ va_list vl;
34
+ va_start (vl, containerClass);
35
+ id appearance = [UIBarButtonItem appearanceWhenContainedIn: containerClass, nil ];
36
+ va_end (vl);
37
+ [UIBarButtonItem configureItemOrProxy: appearance forFlatButtonWithColor: color highlightedColor: highlightedColor cornerRadius: cornerRadius];
38
38
}
39
39
40
40
- (void ) removeTitleShadow {
41
- NSMutableDictionary *titleTextAttributes = [[self titleTextAttributesForState: UIControlStateNormal] mutableCopy ];
42
- if (!titleTextAttributes) {
43
- titleTextAttributes = [NSMutableDictionary dictionary ];
44
- }
45
- [titleTextAttributes setValue: [NSValue valueWithUIOffset: UIOffsetMake (0 , 0 )] forKey: UITextAttributeTextShadowOffset];
46
- [self setTitleTextAttributes: titleTextAttributes forState: UIControlStateNormal];
41
+ NSMutableDictionary *titleTextAttributes = [[self titleTextAttributesForState: UIControlStateNormal] mutableCopy ];
42
+ if (!titleTextAttributes) {
43
+ titleTextAttributes = [NSMutableDictionary dictionary ];
44
+ }
45
+ [titleTextAttributes setValue: [NSValue valueWithUIOffset: UIOffsetMake (0 , 0 )] forKey: UITextAttributeTextShadowOffset];
46
+ [self setTitleTextAttributes: titleTextAttributes forState: UIControlStateNormal];
47
47
}
48
48
49
49
// helper method, basically a wrapper to allow creating a custom UIAppearance method that doesn't conform to the usual naming style
50
50
+ (void ) configureItemOrProxy : (id )appearance
51
51
forFlatButtonWithColor : (UIColor *)color
52
52
highlightedColor : (UIColor *)highlightedColor
53
53
cornerRadius : (CGFloat) cornerRadius {
54
- UIImage *backButtonPortraitImage = [UIImage backButtonImageWithColor: color
55
- barMetrics: UIBarMetricsDefault
56
- cornerRadius: cornerRadius];
57
- UIImage *highlightedBackButtonPortraitImage = [UIImage backButtonImageWithColor: highlightedColor
58
- barMetrics: UIBarMetricsDefault
59
- cornerRadius: cornerRadius];
60
- UIImage *backButtonLandscapeImage = [UIImage backButtonImageWithColor: color
61
- barMetrics: UIBarMetricsLandscapePhone
62
- cornerRadius: 2 ];
63
- UIImage *highlightedBackButtonLandscapeImage = [UIImage backButtonImageWithColor: highlightedColor
64
- barMetrics: UIBarMetricsLandscapePhone
65
- cornerRadius: 2 ];
66
-
67
- [appearance setBackButtonBackgroundImage: backButtonPortraitImage
68
- forState: UIControlStateNormal
69
- barMetrics: UIBarMetricsDefault];
70
- [appearance setBackButtonBackgroundImage: backButtonLandscapeImage
71
- forState: UIControlStateNormal
72
- barMetrics: UIBarMetricsLandscapePhone];
73
- [appearance setBackButtonBackgroundImage: highlightedBackButtonPortraitImage
74
- forState: UIControlStateHighlighted
75
- barMetrics: UIBarMetricsDefault];
76
- [appearance setBackButtonBackgroundImage: highlightedBackButtonLandscapeImage
77
- forState: UIControlStateHighlighted
78
- barMetrics: UIBarMetricsLandscapePhone];
79
-
80
- [appearance setBackButtonTitlePositionAdjustment: UIOffsetMake (1 .0f , 1 .0f ) forBarMetrics: UIBarMetricsDefault];
81
- [appearance setBackButtonTitlePositionAdjustment: UIOffsetMake (1 .0f , 1 .0f ) forBarMetrics: UIBarMetricsLandscapePhone];
82
-
83
- UIImage *buttonImage = [UIImage imageWithColor: color cornerRadius: cornerRadius];
84
- [appearance setBackgroundImage: buttonImage forState: UIControlStateNormal barMetrics: UIBarMetricsDefault];
85
-
54
+ UIImage *backButtonPortraitImage = [UIImage backButtonImageWithColor: color
55
+ barMetrics: UIBarMetricsDefault
56
+ cornerRadius: cornerRadius];
57
+ UIImage *highlightedBackButtonPortraitImage = [UIImage backButtonImageWithColor: highlightedColor
58
+ barMetrics: UIBarMetricsDefault
59
+ cornerRadius: cornerRadius];
60
+ UIImage *backButtonLandscapeImage = [UIImage backButtonImageWithColor: color
61
+ barMetrics: UIBarMetricsLandscapePhone
62
+ cornerRadius: 2 ];
63
+ UIImage *highlightedBackButtonLandscapeImage = [UIImage backButtonImageWithColor: highlightedColor
64
+ barMetrics: UIBarMetricsLandscapePhone
65
+ cornerRadius: 2 ];
66
+
67
+ [appearance setBackButtonBackgroundImage: backButtonPortraitImage
68
+ forState: UIControlStateNormal
69
+ barMetrics: UIBarMetricsDefault];
70
+ [appearance setBackButtonBackgroundImage: backButtonLandscapeImage
71
+ forState: UIControlStateNormal
72
+ barMetrics: UIBarMetricsLandscapePhone];
73
+ [appearance setBackButtonBackgroundImage: highlightedBackButtonPortraitImage
74
+ forState: UIControlStateHighlighted
75
+ barMetrics: UIBarMetricsDefault];
76
+ [appearance setBackButtonBackgroundImage: highlightedBackButtonLandscapeImage
77
+ forState: UIControlStateHighlighted
78
+ barMetrics: UIBarMetricsLandscapePhone];
79
+
80
+ [appearance setBackButtonTitlePositionAdjustment: UIOffsetMake (1 .0f , 1 .0f ) forBarMetrics: UIBarMetricsDefault];
81
+ [appearance setBackButtonTitlePositionAdjustment: UIOffsetMake (1 .0f , 1 .0f ) forBarMetrics: UIBarMetricsLandscapePhone];
82
+
83
+ UIImage *buttonImageNormal = [UIImage imageWithColor: color cornerRadius: cornerRadius];
84
+ UIImage *buttonImageHightlighted = [UIImage imageWithColor: highlightedColor cornerRadius: cornerRadius];
85
+ [appearance setBackgroundImage: buttonImageNormal forState: UIControlStateNormal barMetrics: UIBarMetricsDefault];
86
+ [appearance setBackgroundImage: buttonImageHightlighted forState: UIControlStateHighlighted barMetrics: UIBarMetricsDefault];
86
87
}
87
88
88
-
89
89
@end
0 commit comments