From 719d9e875537a9101994bd846d0cf5abed38041d Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Mon, 17 Oct 2016 15:18:16 +0200 Subject: [PATCH 01/14] aggiornato podspec --- Class/DYSlideView.h | 3 ++- Class/DYSlideView.m | 21 +++++++-------------- DYSlideView.podspec | 4 ++-- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Class/DYSlideView.h b/Class/DYSlideView.h index 1e05ccd..c07d13e 100644 --- a/Class/DYSlideView.h +++ b/Class/DYSlideView.h @@ -13,7 +13,7 @@ @required - (NSInteger)DY_numberOfViewControllersInSlideView; -- (NSString *)DY_titleForViewControllerAtIndex:(NSInteger)index; +- (NSAttributedString *)DY_attributedtitleForViewControllerAtIndex:(NSInteger)index; - (UIViewController *)DY_viewControllerAtIndex:(NSInteger)index; @optional @@ -27,6 +27,7 @@ @property (nonatomic, weak) id delegate; @property (strong, nonatomic) NSNumber *indexForDefaultItem; +@property (nonatomic, assign, readonly) NSInteger currentSelectedIndex; @property (strong, nonatomic) UIColor *slideBarColor; @property (nonatomic) CGFloat slideBarHeight; diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index 3008abc..ed21952 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -14,7 +14,6 @@ @interface DYSlideView () { UIView * _slider; NSMutableArray *_slideBarButtons; UIButton * _selectedButton; - NSInteger _currentBtnIndex; UIScrollView *_scrollView; } @@ -86,7 +85,7 @@ - (void)layoutSubviews { } else { [self updateSelectedButton:nil]; } - [_selectedButton setTitleColor:_buttonSelectedColor forState:UIControlStateNormal]; + [[_slideBarButtons objectAtIndex:_currentSelectedIndex] setAttributedTitle:[_delegate DY_attributedtitleForViewControllerAtIndex:_currentSelectedIndex] forState:UIControlStateNormal]; } } @@ -110,9 +109,7 @@ - (void)addButtons { [button setFrame:CGRectMake( width * i, 5, width, 35)]; [button setTag:i]; [button.titleLabel setTextAlignment:NSTextAlignmentCenter]; - [button.titleLabel setFont:_buttonTitleFont]; - [button setTitleColor:_buttonNormalColor forState:UIControlStateNormal]; - [button setTitle:[_delegate DY_titleForViewControllerAtIndex:i]?:@"" forState:UIControlStateNormal]; + [button setAttributedTitle:[_delegate DY_attributedtitleForViewControllerAtIndex:i] forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [_slideBarButtons addObject:button]; @@ -189,20 +186,16 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { index += 1; } - if (index < _numberOfViewControllers && _currentBtnIndex != index) { - _currentBtnIndex = index; - for (UIButton *button in _slideBarButtons) { - if ([_slideBarButtons indexOfObject:button] == _currentBtnIndex) { - [[_slideBarButtons objectAtIndex:_currentBtnIndex] setTitleColor:_buttonSelectedColor forState:UIControlStateNormal]; - } else { - [button setTitleColor:_buttonNormalColor forState:UIControlStateNormal]; - } + if (index < _numberOfViewControllers && _currentSelectedIndex != index) { + _currentSelectedIndex = index; + for ( NSInteger b = 0; b < [_slideBarButtons count]; b++) { + [_slideBarButtons[b] setAttributedTitle:[_delegate DY_attributedtitleForViewControllerAtIndex:b] forState:UIControlStateNormal]; } } } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ - [self updateSelectedButton:[_slideBarButtons objectAtIndex:_currentBtnIndex]]; + [self updateSelectedButton:[_slideBarButtons objectAtIndex:_currentSelectedIndex]]; } @end diff --git a/DYSlideView.podspec b/DYSlideView.podspec index 15bdb24..f21a222 100644 --- a/DYSlideView.podspec +++ b/DYSlideView.podspec @@ -3,12 +3,12 @@ Pod::Spec.new do |s| s.name = 'DYSlideView' s.version = '0.0.9' s.summary = 'An iOS tabbed slide view.' - s.homepage = 'https://github.com/Dwarven/DYSlideView' + s.homepage = 'https://github.com/tarokker/DYSlideView' s.ios.deployment_target = '7.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'Dwarven' => 'prison.yang@gmail.com' } s.social_media_url = "https://twitter.com/DwarvenYang" - s.source = { :git => 'https://github.com/Dwarven/DYSlideView.git', :tag => s.version } + s.source = { :git => 'https://github.com/tarokker/DYSlideView.git', :tag => s.version } s.source_files = 'Class/*.{h,m}' end From bdae0a55efafb228a6458eee2d596e43148651ef Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Mon, 17 Oct 2016 22:05:20 +0200 Subject: [PATCH 02/14] quasi riscritto DYSlideView per tentare di supportare il resize a seguito di rotation --- Class/DYSlideView.m | 194 +++++++++++++++++++++-------------- DYSlideView/ViewController.m | 8 +- 2 files changed, 122 insertions(+), 80 deletions(-) diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index ed21952..7626a07 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -8,20 +8,23 @@ #import "DYSlideView.h" -@interface DYSlideView () { +@interface DYSlideView () +{ NSInteger _numberOfViewControllers; UIView * _slideBar; UIView * _slider; - NSMutableArray *_slideBarButtons; + NSMutableArray *_slideBarButtons, *_addedControllers; UIButton * _selectedButton; UIScrollView *_scrollView; + BOOL _initializating; } @end @implementation DYSlideView -- (void)dealloc{ +- (void)dealloc +{ _scrollView = nil; _selectedButton = nil; _slideBarButtons = nil; @@ -35,31 +38,40 @@ - (void)dealloc{ _buttonTitleFont = nil; } -- (id)init { +- (id)init +{ self = [super init]; - if (self) { + if (self) + { [self setupForInitialization]; } return self; } -- (id)initWithFrame:(CGRect)frame{ +- (id)initWithFrame:(CGRect)frame +{ self = [super initWithFrame:frame]; - if (self) { + if (self) + { [self setupForInitialization]; } return self; } -- (id)initWithCoder:(NSCoder *)aDecoder{ +- (id)initWithCoder:(NSCoder *)aDecoder +{ self = [super initWithCoder:aDecoder]; - if (self) { + if (self) + { [self setupForInitialization]; } return self; } -- (void)setupForInitialization { +- (void)setupForInitialization +{ + _initializating = YES; + _numberOfViewControllers = NSNotFound; _slideBarColor = [UIColor lightGrayColor]; _sliderColor = [UIColor redColor];; _buttonNormalColor = [UIColor whiteColor]; @@ -72,69 +84,60 @@ - (void)setupForInitialization { _scrollEnabled = YES; } -- (void)layoutSubviews { +- (void)layoutSubviews +{ [super layoutSubviews]; - if (!_slideBarButtons) { + + if ( _initializating ) + { _numberOfViewControllers = [self.delegate DY_numberOfViewControllersInSlideView]; - [self addSlideBar]; - [self addScrollView]; - if (_indexForDefaultItem && [_slideBarButtons count] > [_indexForDefaultItem integerValue]) { - UIButton * button = [_slideBarButtons objectAtIndex:[_indexForDefaultItem integerValue]]; - [self updateSelectedButton:button]; - [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * button.tag, 0) animated:NO]; - } else { - [self updateSelectedButton:nil]; - } - [[_slideBarButtons objectAtIndex:_currentSelectedIndex] setAttributedTitle:[_delegate DY_attributedtitleForViewControllerAtIndex:_currentSelectedIndex] forState:UIControlStateNormal]; - } -} - -- (void)addSlideBar { - if (!_slideBar) { - _slideBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, _slideBarHeight)]; + _slideBar = [[UIView alloc] initWithFrame:CGRectZero]; [_slideBar setBackgroundColor:_slideBarColor]; [self addSubview:_slideBar]; } - [self addButtons]; - [self addSlider]; -} - -- (void)addButtons { - _slideBarButtons = [NSMutableArray array]; - for (NSInteger i = 0; i < _numberOfViewControllers; i++) { - + [_slideBar setFrame:CGRectMake(0, 0, self.bounds.size.width, _slideBarHeight)]; + + if ( _initializating ) + { + _slideBarButtons = [NSMutableArray array]; + for (NSInteger i = 0; i < _numberOfViewControllers; i++) + { + UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; + [button setFrame:CGRectZero]; + [button setTag:i]; + [button.titleLabel setTextAlignment:NSTextAlignmentCenter]; + [button setAttributedTitle:[_delegate DY_attributedtitleForViewControllerAtIndex:i] forState:UIControlStateNormal]; + [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; + [_slideBarButtons addObject:button]; + [_slideBar addSubview:button]; + } + } + + for (NSInteger i = 0; i < _numberOfViewControllers; i++) + { + UIButton *button = _slideBarButtons[i]; CGFloat width = self.bounds.size.width / _numberOfViewControllers; - - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setFrame:CGRectMake( width * i, 5, width, 35)]; - [button setTag:i]; - [button.titleLabel setTextAlignment:NSTextAlignmentCenter]; - [button setAttributedTitle:[_delegate DY_attributedtitleForViewControllerAtIndex:i] forState:UIControlStateNormal]; - [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; - - [_slideBarButtons addObject:button]; - [_slideBar addSubview:button]; } -} - -- (void)addSlider { - if (!_slider) { - CGFloat buttonWidth = self.bounds.size.width / _numberOfViewControllers; - CGFloat sliderWidth = buttonWidth * _sliderScale; - - _slider = [[UIView alloc] initWithFrame:CGRectMake((buttonWidth - sliderWidth)/2, _slideBarHeight-_sliderHeight, sliderWidth, _sliderHeight)]; - [_slider setBackgroundColor:_sliderColor]; + + CGFloat buttonWidth = self.bounds.size.width / _numberOfViewControllers; + CGFloat sliderWidth = buttonWidth * _sliderScale; + + if ( _initializating ) + { + _slider = [[UIView alloc] initWithFrame:CGRectZero]; [_slideBar addSubview:_slider]; + [_slider setBackgroundColor:_sliderColor]; } -} - -- (void)addScrollView { - if (!_scrollView) { + [_slider setFrame:CGRectMake((buttonWidth - sliderWidth)/2, _slideBarHeight-_sliderHeight, sliderWidth, _sliderHeight)]; + + if ( _initializating ) + { + _addedControllers = [[NSMutableArray alloc] init]; _scrollView = [[UIScrollView alloc] init]; - [_scrollView setFrame:CGRectMake(0, _slideBarHeight, self.bounds.size.width, self.bounds.size.height - _slideBarHeight)]; + [_scrollView setFrame:CGRectZero]; [_scrollView setDirectionalLockEnabled:YES]; [_scrollView setPagingEnabled:YES]; - [_scrollView setContentSize:CGSizeMake(_scrollView.bounds.size.width * _numberOfViewControllers, 0)]; [_scrollView setShowsHorizontalScrollIndicator:NO]; [_scrollView setDelegate:self]; [_scrollView setBounces:_scrollViewBounces]; @@ -142,36 +145,69 @@ - (void)addScrollView { [self addSubview:_scrollView]; - for (NSInteger i = 0; i < _numberOfViewControllers; i++ ) { + for (NSInteger i = 0; i < _numberOfViewControllers; i++ ) + { UIViewController * vc = [_delegate DY_viewControllerAtIndex:i]; - if (vc) { - CGRect rect = _scrollView.bounds; - rect.origin.x = self.bounds.size.width * i; - [vc.view setFrame:rect]; - [_scrollView addSubview:vc.view]; - } + [_addedControllers addObject:vc ? vc : [NSNull null]]; + [_scrollView addSubview:vc.view]; } } + [_scrollView setFrame:CGRectMake(0, _slideBarHeight, self.bounds.size.width, self.bounds.size.height - _slideBarHeight)]; + [_scrollView setContentSize:CGSizeMake(_scrollView.bounds.size.width * _numberOfViewControllers, 0)]; + + for (NSInteger i = 0; i < _numberOfViewControllers; i++ ) + { + if ( [_addedControllers[i] isEqual:[NSNull null]] ) continue; + UIViewController *vc = _addedControllers[i]; + + CGRect rect = _scrollView.bounds; + rect.origin.x = self.bounds.size.width * i; + [vc.view setFrame:rect]; + } + + if (_indexForDefaultItem && [_slideBarButtons count] > [_indexForDefaultItem integerValue]) + { + UIButton * button = [_slideBarButtons objectAtIndex:[_indexForDefaultItem integerValue]]; + [self updateSelectedButton:button]; + [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * button.tag, 0) animated:NO]; + } + else + { + [self updateSelectedButton:nil]; + } + + if ( _initializating ) + { + [[_slideBarButtons objectAtIndex:_currentSelectedIndex] setAttributedTitle:[_delegate DY_attributedtitleForViewControllerAtIndex:_currentSelectedIndex] forState:UIControlStateNormal]; + } + + _initializating = NO; } -- (void)buttonClicked:(UIButton *)button { +- (void)buttonClicked:(UIButton *)button +{ [self updateSelectedButton:button]; [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * button.tag, 0) animated:YES]; } -- (void)updateSelectedButton:(UIButton *)button{ - if (button == nil && [_slideBarButtons count] > 0) { +- (void)updateSelectedButton:(UIButton *)button +{ + if (button == nil && [_slideBarButtons count] > 0) + { button = [_slideBarButtons firstObject]; } - if (!(_selectedButton && [_slideBarButtons indexOfObject:_selectedButton] == [button tag])) { + if (!(_selectedButton && [_slideBarButtons indexOfObject:_selectedButton] == [button tag])) + { _selectedButton = button; - if (_delegate && [_delegate respondsToSelector:@selector(DY_didSelectButtonAtIndex:)]) { + if (_delegate && [_delegate respondsToSelector:@selector(DY_didSelectButtonAtIndex:)]) + { [self.delegate DY_didSelectButtonAtIndex:[_selectedButton tag]]; } } } -- (void)scrollViewDidScroll:(UIScrollView *)scrollView { +- (void)scrollViewDidScroll:(UIScrollView *)scrollView +{ CGPoint contentOffset = scrollView.contentOffset; CGFloat buttonWidth = self.bounds.size.width / _numberOfViewControllers; @@ -182,19 +218,23 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat ratio = contentOffset.x/self.bounds.size.width; NSInteger index = (NSInteger)ratio; - if (ratio - (NSInteger)ratio >= 0.5) { + if (ratio - (NSInteger)ratio >= 0.5) + { index += 1; } - if (index < _numberOfViewControllers && _currentSelectedIndex != index) { + if (index < _numberOfViewControllers && _currentSelectedIndex != index) + { _currentSelectedIndex = index; - for ( NSInteger b = 0; b < [_slideBarButtons count]; b++) { + for ( NSInteger b = 0; b < [_slideBarButtons count]; b++) + { [_slideBarButtons[b] setAttributedTitle:[_delegate DY_attributedtitleForViewControllerAtIndex:b] forState:UIControlStateNormal]; } } } -- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView +{ [self updateSelectedButton:[_slideBarButtons objectAtIndex:_currentSelectedIndex]]; } diff --git a/DYSlideView/ViewController.m b/DYSlideView/ViewController.m index 38bc8d6..7963fa2 100644 --- a/DYSlideView/ViewController.m +++ b/DYSlideView/ViewController.m @@ -19,6 +19,7 @@ - (void)viewDidLoad { [super viewDidLoad]; DYSlideView *slideView = [[DYSlideView alloc] init]; + [slideView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; [slideView setFrame:self.view.bounds]; slideView.slideBarColor = [UIColor lightGrayColor]; @@ -26,7 +27,7 @@ - (void)viewDidLoad { slideView.sliderColor = [UIColor redColor]; slideView.sliderHeight = 2; - slideView.sliderScale = 0.6; +// slideView.sliderScale = 0.6; slideView.buttonNormalColor = [UIColor yellowColor]; slideView.buttonSelectedColor = [UIColor blackColor]; @@ -45,8 +46,9 @@ - (NSInteger)DY_numberOfViewControllersInSlideView { return 4; } -- (NSString *)DY_titleForViewControllerAtIndex:(NSInteger)index{ - return [NSString stringWithFormat:@"Tab%li",index]; +- (NSAttributedString *)DY_attributedtitleForViewControllerAtIndex:(NSInteger)index +{ + return [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"Tab%li",index] attributes:nil]; } - (UIViewController *)DY_viewControllerAtIndex:(NSInteger)index { From c81c27f7e2e469796fd4ac23944540e466c23428 Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Thu, 20 Oct 2016 18:26:32 +0200 Subject: [PATCH 03/14] rimossi colori inutili nel DYSlideView --- Class/DYSlideView.h | 4 ---- Class/DYSlideView.m | 6 ------ DYSlideView/ViewController.m | 4 ---- 3 files changed, 14 deletions(-) diff --git a/Class/DYSlideView.h b/Class/DYSlideView.h index c07d13e..5420e7e 100644 --- a/Class/DYSlideView.h +++ b/Class/DYSlideView.h @@ -36,10 +36,6 @@ @property (nonatomic) CGFloat sliderHeight; @property (nonatomic) CGFloat sliderScale; -@property (strong, nonatomic) UIColor *buttonNormalColor; -@property (strong, nonatomic) UIColor *buttonSelectedColor; -@property (strong, nonatomic) UIFont *buttonTitleFont; - @property (nonatomic) BOOL scrollViewBounces; @property (nonatomic) BOOL scrollEnabled; diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index 7626a07..333c3c3 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -33,9 +33,6 @@ - (void)dealloc _indexForDefaultItem = nil; _slideBarColor = nil; _sliderColor = nil; - _buttonNormalColor = nil; - _buttonSelectedColor = nil; - _buttonTitleFont = nil; } - (id)init @@ -74,12 +71,9 @@ - (void)setupForInitialization _numberOfViewControllers = NSNotFound; _slideBarColor = [UIColor lightGrayColor]; _sliderColor = [UIColor redColor];; - _buttonNormalColor = [UIColor whiteColor]; - _buttonSelectedColor = [UIColor blackColor]; _sliderScale = 1.f; _slideBarHeight = 50.f; _sliderHeight = 4.f; - _buttonTitleFont = [UIFont systemFontOfSize:16.f]; _scrollViewBounces = YES; _scrollEnabled = YES; } diff --git a/DYSlideView/ViewController.m b/DYSlideView/ViewController.m index 7963fa2..fcdef3d 100644 --- a/DYSlideView/ViewController.m +++ b/DYSlideView/ViewController.m @@ -29,10 +29,6 @@ - (void)viewDidLoad { slideView.sliderHeight = 2; // slideView.sliderScale = 0.6; - slideView.buttonNormalColor = [UIColor yellowColor]; - slideView.buttonSelectedColor = [UIColor blackColor]; - slideView.buttonTitleFont = [UIFont boldSystemFontOfSize:16.f]; - slideView.scrollViewBounces = YES; slideView.indexForDefaultItem = @0; From e87b110d44f6d4dc4646d8617e4792b58a170592 Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Thu, 20 Oct 2016 18:32:30 +0200 Subject: [PATCH 04/14] aggiunto codice per separatore in DYSlideView --- Class/DYSlideView.h | 2 ++ Class/DYSlideView.m | 15 +++++++++++++++ DYSlideView/ViewController.m | 1 + 3 files changed, 18 insertions(+) diff --git a/Class/DYSlideView.h b/Class/DYSlideView.h index 5420e7e..61b5a17 100644 --- a/Class/DYSlideView.h +++ b/Class/DYSlideView.h @@ -36,6 +36,8 @@ @property (nonatomic) CGFloat sliderHeight; @property (nonatomic) CGFloat sliderScale; +@property (nonatomic, strong) UIColor *separatorColor; + @property (nonatomic) BOOL scrollViewBounces; @property (nonatomic) BOOL scrollEnabled; diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index 333c3c3..51a5bab 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -13,6 +13,7 @@ @interface DYSlideView () NSInteger _numberOfViewControllers; UIView * _slideBar; UIView * _slider; + UIView *_separator; NSMutableArray *_slideBarButtons, *_addedControllers; UIButton * _selectedButton; UIScrollView *_scrollView; @@ -25,6 +26,8 @@ @implementation DYSlideView - (void)dealloc { + _separator = nil; + _separatorColor = nil; _scrollView = nil; _selectedButton = nil; _slideBarButtons = nil; @@ -114,6 +117,18 @@ - (void)layoutSubviews [button setFrame:CGRectMake( width * i, 5, width, 35)]; } + if ( _initializating ) + { + if ( _separatorColor ) + { + _separator = [[UIView alloc] initWithFrame:CGRectZero]; + [_separator setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin]; + [_separator setBackgroundColor:_separatorColor]; + [_slideBar addSubview:_separator]; + } + } + [_separator setFrame:CGRectMake(0, _slideBarHeight - _sliderHeight + 1, _slideBar.bounds.size.width, 1.0)]; + CGFloat buttonWidth = self.bounds.size.width / _numberOfViewControllers; CGFloat sliderWidth = buttonWidth * _sliderScale; diff --git a/DYSlideView/ViewController.m b/DYSlideView/ViewController.m index fcdef3d..aa5b8a5 100644 --- a/DYSlideView/ViewController.m +++ b/DYSlideView/ViewController.m @@ -22,6 +22,7 @@ - (void)viewDidLoad { [slideView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; [slideView setFrame:self.view.bounds]; + slideView.separatorColor = [UIColor yellowColor]; slideView.slideBarColor = [UIColor lightGrayColor]; slideView.slideBarHeight = 50; From 249d25aae3f0e35bd2486395ef021fd042ebf90a Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Fri, 4 Nov 2016 13:00:09 +0100 Subject: [PATCH 05/14] gestione riselezione elemento dopo il layoutsubview --- Class/DYSlideView.m | 29 ++++++++++++++++----------- DYSlideView.xcodeproj/project.pbxproj | 2 ++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index 51a5bab..1162d9b 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -174,22 +174,27 @@ - (void)layoutSubviews [vc.view setFrame:rect]; } - if (_indexForDefaultItem && [_slideBarButtons count] > [_indexForDefaultItem integerValue]) - { - UIButton * button = [_slideBarButtons objectAtIndex:[_indexForDefaultItem integerValue]]; - [self updateSelectedButton:button]; - [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * button.tag, 0) animated:NO]; - } - else - { - [self updateSelectedButton:nil]; - } - if ( _initializating ) { + if (_indexForDefaultItem && [_slideBarButtons count] > [_indexForDefaultItem integerValue]) + { + UIButton * button = [_slideBarButtons objectAtIndex:[_indexForDefaultItem integerValue]]; + [self updateSelectedButton:button]; + [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * button.tag, 0) animated:NO]; + } + else + { + [self updateSelectedButton:nil]; + } + [[_slideBarButtons objectAtIndex:_currentSelectedIndex] setAttributedTitle:[_delegate DY_attributedtitleForViewControllerAtIndex:_currentSelectedIndex] forState:UIControlStateNormal]; } - + // 04/11/2016 - inserito questo per tentare di gestire il refresh quando ruoti, dopo l'init + else if ( _selectedButton ) + { + [self updateSelectedButton:_selectedButton]; + [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * _selectedButton.tag, 0) animated:NO]; + } _initializating = NO; } diff --git a/DYSlideView.xcodeproj/project.pbxproj b/DYSlideView.xcodeproj/project.pbxproj index 6c82db8..9b8e0f0 100644 --- a/DYSlideView.xcodeproj/project.pbxproj +++ b/DYSlideView.xcodeproj/project.pbxproj @@ -420,6 +420,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.Dwarven.DYSlideView; PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -432,6 +433,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.Dwarven.DYSlideView; PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; From 73ea4c50ce2cec9d77eb24675ebcc3509e5cf4dd Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Fri, 4 Nov 2016 13:00:40 +0100 Subject: [PATCH 06/14] aggiornato pod spec --- DYSlideView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DYSlideView.podspec b/DYSlideView.podspec index f21a222..c7b3a83 100644 --- a/DYSlideView.podspec +++ b/DYSlideView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'DYSlideView' - s.version = '0.0.9' + s.version = '0.0.10' s.summary = 'An iOS tabbed slide view.' s.homepage = 'https://github.com/tarokker/DYSlideView' s.ios.deployment_target = '7.0' From ae46856a5c1516071ee1d80f0571666f68800053 Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Tue, 22 Nov 2016 10:29:22 +0100 Subject: [PATCH 07/14] aggiunto metodo scroll --- Class/DYSlideView.h | 1 + Class/DYSlideView.m | 30 ++++++++++++++++++++++++------ DYSlideView.podspec | 2 +- DYSlideView/ViewController.m | 2 ++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Class/DYSlideView.h b/Class/DYSlideView.h index 61b5a17..abd6d9b 100644 --- a/Class/DYSlideView.h +++ b/Class/DYSlideView.h @@ -41,5 +41,6 @@ @property (nonatomic) BOOL scrollViewBounces; @property (nonatomic) BOOL scrollEnabled; +- (void)selectButtonWithIndex:(NSInteger)newIndex; @end diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index 1162d9b..9f0c708 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -20,6 +20,8 @@ @interface DYSlideView () BOOL _initializating; } +- (void)_updateSelectedButton:(UIButton *)button; + @end @implementation DYSlideView @@ -179,12 +181,12 @@ - (void)layoutSubviews if (_indexForDefaultItem && [_slideBarButtons count] > [_indexForDefaultItem integerValue]) { UIButton * button = [_slideBarButtons objectAtIndex:[_indexForDefaultItem integerValue]]; - [self updateSelectedButton:button]; + [self _updateSelectedButton:button]; [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * button.tag, 0) animated:NO]; } else { - [self updateSelectedButton:nil]; + [self _updateSelectedButton:nil]; } [[_slideBarButtons objectAtIndex:_currentSelectedIndex] setAttributedTitle:[_delegate DY_attributedtitleForViewControllerAtIndex:_currentSelectedIndex] forState:UIControlStateNormal]; @@ -192,7 +194,7 @@ - (void)layoutSubviews // 04/11/2016 - inserito questo per tentare di gestire il refresh quando ruoti, dopo l'init else if ( _selectedButton ) { - [self updateSelectedButton:_selectedButton]; + [self _updateSelectedButton:_selectedButton]; [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * _selectedButton.tag, 0) animated:NO]; } _initializating = NO; @@ -200,11 +202,11 @@ - (void)layoutSubviews - (void)buttonClicked:(UIButton *)button { - [self updateSelectedButton:button]; + [self _updateSelectedButton:button]; [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * button.tag, 0) animated:YES]; } -- (void)updateSelectedButton:(UIButton *)button +- (void)_updateSelectedButton:(UIButton *)button { if (button == nil && [_slideBarButtons count] > 0) { @@ -220,6 +222,22 @@ - (void)updateSelectedButton:(UIButton *)button } } +- (void)selectButtonWithIndex:(NSInteger)newIndex +{ + [self layoutIfNeeded]; + for ( UIButton *mButton in _slideBarButtons ) + { + if ( mButton.tag == newIndex ) + { + dispatch_async(dispatch_get_main_queue(), ^{ + [self _updateSelectedButton:mButton]; + [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * mButton.tag, 0) animated:NO]; + }); + return; + } + } +} + - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGPoint contentOffset = scrollView.contentOffset; @@ -249,7 +267,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { - [self updateSelectedButton:[_slideBarButtons objectAtIndex:_currentSelectedIndex]]; + [self _updateSelectedButton:[_slideBarButtons objectAtIndex:_currentSelectedIndex]]; } @end diff --git a/DYSlideView.podspec b/DYSlideView.podspec index c7b3a83..27bf22a 100644 --- a/DYSlideView.podspec +++ b/DYSlideView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'DYSlideView' - s.version = '0.0.10' + s.version = '0.0.11' s.summary = 'An iOS tabbed slide view.' s.homepage = 'https://github.com/tarokker/DYSlideView' s.ios.deployment_target = '7.0' diff --git a/DYSlideView/ViewController.m b/DYSlideView/ViewController.m index aa5b8a5..a059f47 100644 --- a/DYSlideView/ViewController.m +++ b/DYSlideView/ViewController.m @@ -37,6 +37,8 @@ - (void)viewDidLoad { slideView.delegate = self; [self.view addSubview:slideView]; + [slideView selectButtonWithIndex:1]; + } - (NSInteger)DY_numberOfViewControllersInSlideView { From 3d60bfc35fb634631627b1ed84934d6c5ffa6f8b Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Tue, 22 Nov 2016 11:44:55 +0100 Subject: [PATCH 08/14] testo cambio logica selectButtonWithIndex --- Class/DYSlideView.m | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index 9f0c708..71f2324 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -224,15 +224,14 @@ - (void)_updateSelectedButton:(UIButton *)button - (void)selectButtonWithIndex:(NSInteger)newIndex { - [self layoutIfNeeded]; for ( UIButton *mButton in _slideBarButtons ) { if ( mButton.tag == newIndex ) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self _updateSelectedButton:mButton]; - [_scrollView setContentOffset:CGPointMake(self.bounds.size.width * mButton.tag, 0) animated:NO]; - }); + _selectedButton = mButton; + _indexForDefaultItem = [NSNumber numberWithInteger:_selectedButton.tag]; + [self setNeedsLayout]; + [self layoutIfNeeded]; return; } } From 15074b9de1233737cb2585bb856ea5a4053c88e1 Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Tue, 22 Nov 2016 11:45:08 +0100 Subject: [PATCH 09/14] aggiornato --- DYSlideView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DYSlideView.podspec b/DYSlideView.podspec index 27bf22a..85d26d3 100644 --- a/DYSlideView.podspec +++ b/DYSlideView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'DYSlideView' - s.version = '0.0.11' + s.version = '0.0.12' s.summary = 'An iOS tabbed slide view.' s.homepage = 'https://github.com/tarokker/DYSlideView' s.ios.deployment_target = '7.0' From 93935f8fd39f36e3f7461166d7eb79ef2566ca03 Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Tue, 22 Nov 2016 11:55:58 +0100 Subject: [PATCH 10/14] aggiornato forse funzionante selezione --- Class/DYSlideView.m | 20 +++++++++++++------- DYSlideView.podspec | 2 +- DYSlideView/ViewController.m | 26 ++++++++++++++++++-------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index 71f2324..f2400fa 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -224,15 +224,21 @@ - (void)_updateSelectedButton:(UIButton *)button - (void)selectButtonWithIndex:(NSInteger)newIndex { - for ( UIButton *mButton in _slideBarButtons ) + if ( _initializating ) + { + _indexForDefaultItem = [NSNumber numberWithInteger:newIndex]; + } + else { - if ( mButton.tag == newIndex ) + for ( UIButton *mButton in _slideBarButtons ) { - _selectedButton = mButton; - _indexForDefaultItem = [NSNumber numberWithInteger:_selectedButton.tag]; - [self setNeedsLayout]; - [self layoutIfNeeded]; - return; + if ( mButton.tag == newIndex ) + { + _selectedButton = mButton; + [self setNeedsLayout]; + [self layoutIfNeeded]; + return; + } } } } diff --git a/DYSlideView.podspec b/DYSlideView.podspec index 85d26d3..eac4e88 100644 --- a/DYSlideView.podspec +++ b/DYSlideView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'DYSlideView' - s.version = '0.0.12' + s.version = '0.0.13' s.summary = 'An iOS tabbed slide view.' s.homepage = 'https://github.com/tarokker/DYSlideView' s.ios.deployment_target = '7.0' diff --git a/DYSlideView/ViewController.m b/DYSlideView/ViewController.m index a059f47..d60f08a 100644 --- a/DYSlideView/ViewController.m +++ b/DYSlideView/ViewController.m @@ -10,7 +10,9 @@ #import "DYSlideView.h" @interface ViewController () - +{ + DYSlideView *slideView; +} @end @implementation ViewController @@ -18,7 +20,7 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - DYSlideView *slideView = [[DYSlideView alloc] init]; + slideView = [[DYSlideView alloc] init]; [slideView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; [slideView setFrame:self.view.bounds]; @@ -36,9 +38,6 @@ - (void)viewDidLoad { slideView.delegate = self; [self.view addSubview:slideView]; - - [slideView selectButtonWithIndex:1]; - } - (NSInteger)DY_numberOfViewControllersInSlideView { @@ -53,9 +52,16 @@ - (NSAttributedString *)DY_attributedtitleForViewControllerAtIndex:(NSInteger)in - (UIViewController *)DY_viewControllerAtIndex:(NSInteger)index { switch (index) { case 0: - return [self vcWithBackgroundColor:[UIColor whiteColor]]; - break; - + { + UIViewController *newctl = [self vcWithBackgroundColor:[UIColor whiteColor]]; + UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; + [btn setBackgroundColor:[UIColor blueColor]]; + [btn setTitle:@"Go 2" forState:UIControlStateNormal]; + [btn addTarget:self action:@selector(didClickButtonGo2:) forControlEvents:UIControlEventTouchUpInside]; + [btn setFrame:CGRectMake(50, 50, 150, 50)]; + [newctl.view addSubview:btn]; + return newctl; + } case 1: return [self vcWithBackgroundColor:[UIColor grayColor]]; break; @@ -84,4 +90,8 @@ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } +- (void)didClickButtonGo2:(id)sender +{ + [slideView selectButtonWithIndex:1]; +} @end From e9ea73dd271a45fdf87a4f804ac4f3454d991edd Mon Sep 17 00:00:00 2001 From: Daniele Maiorana Date: Mon, 17 Jul 2017 18:21:29 +0200 Subject: [PATCH 11/14] aggiornata versione --- Class/DYSlideView.m | 7 ++++--- DYSlideView.podspec | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index f2400fa..9945390 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -130,7 +130,7 @@ - (void)layoutSubviews } } [_separator setFrame:CGRectMake(0, _slideBarHeight - _sliderHeight + 1, _slideBar.bounds.size.width, 1.0)]; - + CGFloat buttonWidth = self.bounds.size.width / _numberOfViewControllers; CGFloat sliderWidth = buttonWidth * _sliderScale; @@ -140,7 +140,7 @@ - (void)layoutSubviews [_slideBar addSubview:_slider]; [_slider setBackgroundColor:_sliderColor]; } - [_slider setFrame:CGRectMake((buttonWidth - sliderWidth)/2, _slideBarHeight-_sliderHeight, sliderWidth, _sliderHeight)]; + [_slider setFrame:CGRectMake((buttonWidth - sliderWidth)/2, _slideBarHeight-_sliderHeight-1, sliderWidth, _sliderHeight)]; if ( _initializating ) { @@ -251,7 +251,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView CGFloat sliderWidth = buttonWidth * _sliderScale; CGRect rect = _slider.frame; rect.origin.x = (contentOffset.x/self.bounds.size.width) * buttonWidth + (buttonWidth - sliderWidth)/2; - [_slider setFrame:rect]; + [_slider setFrame:CGRectMake(rect.origin.x, _slideBarHeight-_sliderHeight-1, sliderWidth, _sliderHeight)]; + CGFloat ratio = contentOffset.x/self.bounds.size.width; NSInteger index = (NSInteger)ratio; diff --git a/DYSlideView.podspec b/DYSlideView.podspec index eac4e88..27aa877 100644 --- a/DYSlideView.podspec +++ b/DYSlideView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'DYSlideView' - s.version = '0.0.13' + s.version = '0.0.14' s.summary = 'An iOS tabbed slide view.' s.homepage = 'https://github.com/tarokker/DYSlideView' s.ios.deployment_target = '7.0' From 2b273760d8f0f5a8779890f0049c4a079137b3db Mon Sep 17 00:00:00 2001 From: "sattar.falahati" Date: Thu, 14 Sep 2017 12:50:57 +0200 Subject: [PATCH 12/14] Change the selected button behavior --- Class/DYSlideView.m | 1 + DYSlideView.podspec | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index 9945390..7b42eda 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -237,6 +237,7 @@ - (void)selectButtonWithIndex:(NSInteger)newIndex _selectedButton = mButton; [self setNeedsLayout]; [self layoutIfNeeded]; + [self _updateSelectedButton:[_slideBarButtons objectAtIndex:newIndex]]; return; } } diff --git a/DYSlideView.podspec b/DYSlideView.podspec index 27aa877..9745c7b 100644 --- a/DYSlideView.podspec +++ b/DYSlideView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'DYSlideView' - s.version = '0.0.14' + s.version = '0.0.15' s.summary = 'An iOS tabbed slide view.' s.homepage = 'https://github.com/tarokker/DYSlideView' s.ios.deployment_target = '7.0' From 2a78e4db4c83db20576888daf0d1b5ee208338a1 Mon Sep 17 00:00:00 2001 From: "sattar.falahati" Date: Thu, 14 Sep 2017 16:44:37 +0200 Subject: [PATCH 13/14] Change the selected button behavior --- Class/DYSlideView.m | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Class/DYSlideView.m b/Class/DYSlideView.m index 7b42eda..33bfe77 100644 --- a/Class/DYSlideView.m +++ b/Class/DYSlideView.m @@ -224,26 +224,25 @@ - (void)_updateSelectedButton:(UIButton *)button - (void)selectButtonWithIndex:(NSInteger)newIndex { - if ( _initializating ) - { + if ( _initializating ) { _indexForDefaultItem = [NSNumber numberWithInteger:newIndex]; } else { - for ( UIButton *mButton in _slideBarButtons ) - { - if ( mButton.tag == newIndex ) - { - _selectedButton = mButton; - [self setNeedsLayout]; - [self layoutIfNeeded]; - [self _updateSelectedButton:[_slideBarButtons objectAtIndex:newIndex]]; + for ( UIButton *mButton in _slideBarButtons ) { + if ( mButton.tag == newIndex ) { + + [self buttonClicked:mButton]; + // _selectedButton = mButton; + // [self setNeedsLayout]; + // [self layoutIfNeeded]; return; } } } } + - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGPoint contentOffset = scrollView.contentOffset; From d58f2a6660b092caf36dd0e6ba0db55fe237f42b Mon Sep 17 00:00:00 2001 From: "sattar.falahati" Date: Thu, 14 Sep 2017 16:47:20 +0200 Subject: [PATCH 14/14] Change the selected button behavior --- DYSlideView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DYSlideView.podspec b/DYSlideView.podspec index 9745c7b..c7e3bde 100644 --- a/DYSlideView.podspec +++ b/DYSlideView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'DYSlideView' - s.version = '0.0.15' + s.version = '0.0.16' s.summary = 'An iOS tabbed slide view.' s.homepage = 'https://github.com/tarokker/DYSlideView' s.ios.deployment_target = '7.0'