From 7bfe5b7011aec7338a957cea2d7e4f7a51995369 Mon Sep 17 00:00:00 2001 From: Douglas Silveira Machado Date: Sat, 28 Jan 2017 16:36:39 -0200 Subject: [PATCH 1/2] Customized the selected slide bar button font --- Class/DYSlideView.h | 1 + Class/DYSlideView.m | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/Class/DYSlideView.h b/Class/DYSlideView.h index 1e05ccd..b4da568 100644 --- a/Class/DYSlideView.h +++ b/Class/DYSlideView.h @@ -38,6 +38,7 @@ @property (strong, nonatomic) UIColor *buttonNormalColor; @property (strong, nonatomic) UIColor *buttonSelectedColor; @property (strong, nonatomic) UIFont *buttonTitleFont; +@property (strong, nonatomic) UIFont *buttonSelectedTitleFont; @property (nonatomic) BOOL scrollViewBounces; @property (nonatomic) BOOL scrollEnabled; diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index 3008abc..c5a506f 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -158,16 +158,25 @@ - (void)addScrollView { } - (void)buttonClicked:(UIButton *)button { + [self configDefaultStyleForSlideBarButtons]; [self updateSelectedButton:button]; [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * button.tag, 0) animated:YES]; } +- (void)configDefaultStyleForSlideBarButtons { + for (UIButton *button in _slideBarButtons) { + [button.titleLabel setFont:_buttonTitleFont]; + } +} + - (void)updateSelectedButton:(UIButton *)button{ if (button == nil && [_slideBarButtons count] > 0) { button = [_slideBarButtons firstObject]; } if (!(_selectedButton && [_slideBarButtons indexOfObject:_selectedButton] == [button tag])) { _selectedButton = button; + [_selectedButton.titleLabel setTextAlignment:NSTextAlignmentCenter]; + [_selectedButton.titleLabel setFont:_buttonSelectedTitleFont]; if (_delegate && [_delegate respondsToSelector:@selector(DY_didSelectButtonAtIndex:)]) { [self.delegate DY_didSelectButtonAtIndex:[_selectedButton tag]]; } From a5e1b7fd6af123fab5beed21796e3a0e01dce1b5 Mon Sep 17 00:00:00 2001 From: Douglas Silveira Machado Date: Sat, 28 Jan 2017 17:26:49 -0200 Subject: [PATCH 2/2] Updating selected slide bar font when swiping --- Class/DYSlideView.m | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index c5a506f..6162a2f 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -158,17 +158,10 @@ - (void)addScrollView { } - (void)buttonClicked:(UIButton *)button { - [self configDefaultStyleForSlideBarButtons]; [self updateSelectedButton:button]; [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * button.tag, 0) animated:YES]; } -- (void)configDefaultStyleForSlideBarButtons { - for (UIButton *button in _slideBarButtons) { - [button.titleLabel setFont:_buttonTitleFont]; - } -} - - (void)updateSelectedButton:(UIButton *)button{ if (button == nil && [_slideBarButtons count] > 0) { button = [_slideBarButtons firstObject]; @@ -203,7 +196,9 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { for (UIButton *button in _slideBarButtons) { if ([_slideBarButtons indexOfObject:button] == _currentBtnIndex) { [[_slideBarButtons objectAtIndex:_currentBtnIndex] setTitleColor:_buttonSelectedColor forState:UIControlStateNormal]; + [button.titleLabel setFont:_buttonSelectedTitleFont]; } else { + [button.titleLabel setFont:_buttonTitleFont]; [button setTitleColor:_buttonNormalColor forState:UIControlStateNormal]; } }