Skip to content

Commit 50fd251

Browse files
committed
Merge pull request Grouper#31 from mattglover/fix-barButtonItemHighlighted
Fix for UIBarButtonItem category .. wasn't using the highlightedColor
2 parents 1e017e0 + 645925a commit 50fd251

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

Classes/ios/UIBarButtonItem+FlatUI.m

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,76 +14,76 @@ @implementation UIBarButtonItem (FlatUI)
1414
- (void) configureFlatButtonWithColor:(UIColor *)color
1515
highlightedColor:(UIColor *)highlightedColor
1616
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+
2020
}
2121

2222
+ (void) configureFlatButtonsWithColor:(UIColor *) color
2323
highlightedColor:(UIColor *)highlightedColor
2424
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];
2727
}
2828

2929
+ (void) configureFlatButtonsWithColor:(UIColor *) color
3030
highlightedColor:(UIColor *)highlightedColor
3131
cornerRadius:(CGFloat) cornerRadius
3232
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];
3838
}
3939

4040
- (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];
4747
}
4848

4949
//helper method, basically a wrapper to allow creating a custom UIAppearance method that doesn't conform to the usual naming style
5050
+ (void) configureItemOrProxy:(id)appearance
5151
forFlatButtonWithColor:(UIColor *)color
5252
highlightedColor:(UIColor *)highlightedColor
5353
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];
8687
}
8788

88-
8989
@end

0 commit comments

Comments
 (0)