Skip to content

Commit af41bfa

Browse files
committed
Add properties control the menuButton style, updata pod spec file
1 parent 482c613 commit af41bfa

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

Project/XHScrollMenu/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ - (void)viewDidLoad
5454
}
5555
menu.title = title;
5656

57-
menu.titleColor = [UIColor colorWithWhite:0.141 alpha:1.000];
57+
menu.titleNormalColor = [UIColor colorWithWhite:0.141 alpha:1.000];
5858
menu.titleFont = [UIFont boldSystemFontOfSize:16];
5959
[menus addObject:menu];
6060
}

Source/XHMenu.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
@property (nonatomic, copy) NSString *title;
1414
@property (nonatomic, strong) UIFont *titleFont;
15-
@property (nonatomic, strong) UIColor *titleColor;
15+
@property (nonatomic, strong) UIColor *titleNormalColor;
16+
@property (nonatomic, strong) UIColor *titleSelectedColor;
17+
@property (nonatomic, strong) UIColor *titleHighlightedColor;
1618

1719
@end

Source/XHScrollMenu.m

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ - (void)managerMenusButtonClicked:(UIButton *)sender {
3535

3636
- (void)menuButtonSelected:(UIButton *)sender {
3737
_currentSelectedIndex = sender.tag - kXHMenuButtonBaseTag;
38+
[self.menuButtons enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
39+
if (obj == sender) {
40+
sender.selected = YES;
41+
} else {
42+
UIButton *menuButton = obj;
43+
menuButton.selected = NO;
44+
}
45+
}];
3846
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
3947
[self.scrollView scrollRectToVisibleCenteredOn:sender.frame animated:NO];
4048
} completion:^(BOOL finished) {
@@ -125,9 +133,15 @@ - (UIButton *)getButtonWithMenu:(XHMenu *)menu {
125133
[button setTitle:menu.title forState:UIControlStateNormal];
126134
[button setTitle:menu.title forState:UIControlStateHighlighted];
127135
[button setTitle:menu.title forState:UIControlStateSelected];
128-
[button setTitleColor:menu.titleColor forState:UIControlStateNormal];
129-
[button setTitleColor:menu.titleColor forState:UIControlStateHighlighted];
130-
[button setTitleColor:menu.titleColor forState:UIControlStateSelected];
136+
[button setTitleColor:menu.titleNormalColor forState:UIControlStateNormal];
137+
if (!menu.titleHighlightedColor) {
138+
menu.titleHighlightedColor = menu.titleNormalColor;
139+
}
140+
[button setTitleColor:menu.titleHighlightedColor forState:UIControlStateHighlighted];
141+
if (!menu.titleSelectedColor) {
142+
menu.titleSelectedColor = menu.titleNormalColor;
143+
}
144+
[button setTitleColor:menu.titleSelectedColor forState:UIControlStateSelected];
131145
[button addTarget:self action:@selector(menuButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
132146
return button;
133147
}
@@ -157,8 +171,11 @@ - (void)reloadData {
157171
contentWidth += CGRectGetMaxX(menuButtonFrame);
158172
}
159173

160-
// indicator
174+
161175
if (self.defaultSelectIndex == index) {
176+
menuButton.selected = YES;
177+
178+
// indicator
162179
_indicatorView.alpha = 1.;
163180
[self setupIndicatorFrame:menuButtonFrame animated:NO];
164181
}

XHScrollMenu.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ Pod::Spec.new do |s|
99
s.frameworks = 'Foundation', 'CoreGraphics', 'UIKit'
1010
s.platform = :ios, '5.0'
1111
s.source_files = 'Source'
12-
s.Resources = 'Source/Resources/*'
12+
s.resources = 'Source/Resources/*'
1313
s.requires_arc = true
1414
end

0 commit comments

Comments
 (0)