From 55751b659e6eef825d91133fa2b6ae17ac969ab5 Mon Sep 17 00:00:00 2001 From: David Miscampbell Date: Sat, 14 Mar 2015 14:14:16 +0000 Subject: [PATCH] Changes the viewpageroptionsstartfromsecondtab option to viewpageroptionsinitialindex so the pager can be opened at any index rather than just the first two --- ICViewPager/Controller/HostViewController.m | 2 +- ICViewPager/ICViewPager/ViewPagerController.h | 4 +-- ICViewPager/ICViewPager/ViewPagerController.m | 36 ++++++++++--------- README.md | 2 +- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/ICViewPager/Controller/HostViewController.m b/ICViewPager/Controller/HostViewController.m index b113549..94efe08 100644 --- a/ICViewPager/Controller/HostViewController.m +++ b/ICViewPager/Controller/HostViewController.m @@ -109,7 +109,7 @@ - (UIViewController *)viewPager:(ViewPagerController *)viewPager contentViewCont - (CGFloat)viewPager:(ViewPagerController *)viewPager valueForOption:(ViewPagerOption)option withDefault:(CGFloat)value { switch (option) { - case ViewPagerOptionStartFromSecondTab: + case ViewPagerOptionInitialIndex: return 0.0; case ViewPagerOptionCenterCurrentTab: return 1.0; diff --git a/ICViewPager/ICViewPager/ViewPagerController.h b/ICViewPager/ICViewPager/ViewPagerController.h index 37218a3..8f0d65e 100644 --- a/ICViewPager/ICViewPager/ViewPagerController.h +++ b/ICViewPager/ICViewPager/ViewPagerController.h @@ -15,7 +15,7 @@ * ViewPagerOptionTabOffset: Tab bar's offset from left, defaults to 56.0 * ViewPagerOptionTabWidth: Any tab item's width, defaults to 128.0 * ViewPagerOptionTabLocation: 1.0: Top, 0.0: Bottom, Defaults to Top - * ViewPagerOptionStartFromSecondTab: 1.0: YES, 0.0: NO, defines if view should appear with the 1st or 2nd tab. Defaults to NO + * ViewPagerOptionInitialIndex: Defines which tab the pager should open at. Defaults to 0 (i.e. the first tab). Should be an integer. * ViewPagerOptionCenterCurrentTab: 1.0: YES, 0.0: NO, defines if tabs should be centered, with the given tabWidth. Defaults to NO * ViewPagerOptionFixFormerTabsPositions: 1.0: YES, 0.0: NO, defines if the active tab should be placed margined by the offset amount to the left. Effects only the former tabs. If set 1.0 (YES), first tab will be placed at the same position with the second one, leaving space before itself. Defaults to NO * ViewPagerOptionFixLatterTabsPositions: 1.0: YES, 0.0: NO, like ViewPagerOptionFixFormerTabsPositions, but effects the latter tabs, making them leave space after themselves. Defaults to NO @@ -25,7 +25,7 @@ typedef NS_ENUM(NSUInteger, ViewPagerOption) { ViewPagerOptionTabOffset, ViewPagerOptionTabWidth, ViewPagerOptionTabLocation, - ViewPagerOptionStartFromSecondTab, + ViewPagerOptionInitialIndex, ViewPagerOptionCenterCurrentTab, ViewPagerOptionFixFormerTabsPositions, ViewPagerOptionFixLatterTabsPositions diff --git a/ICViewPager/ICViewPager/ViewPagerController.m b/ICViewPager/ICViewPager/ViewPagerController.m index 7c3ceb4..0719398 100644 --- a/ICViewPager/ICViewPager/ViewPagerController.m +++ b/ICViewPager/ICViewPager/ViewPagerController.m @@ -17,7 +17,7 @@ #define kTabOffset 56.0 #define kTabWidth 128.0 #define kTabLocation 1.0 -#define kStartFromSecondTab 0.0 +#define kInitialIndex 0.0 #define kCenterCurrentTab 0.0 #define kFixFormerTabsPositions 0.0 #define kFixLatterTabsPositions 0.0 @@ -131,7 +131,7 @@ @interface ViewPagerController () self.tabCount) + initialIndex = [NSNumber numberWithFloat:0.0]; - _startFromSecondTab = startFromSecondTab; + _initialIndex = initialIndex; } - (void)setCenterCurrentTab:(NSNumber *)centerCurrentTab { @@ -475,15 +477,15 @@ - (NSNumber *)tabLocation { } return _tabLocation; } -- (NSNumber *)startFromSecondTab { +- (NSNumber *)initialIndex { - if (!_startFromSecondTab) { - CGFloat value = kStartFromSecondTab; + if (!_initialIndex) { + CGFloat value = kInitialIndex; if ([self.delegate respondsToSelector:@selector(viewPager:valueForOption:withDefault:)]) - value = [self.delegate viewPager:self valueForOption:ViewPagerOptionStartFromSecondTab withDefault:value]; - self.startFromSecondTab = [NSNumber numberWithFloat:value]; + value = [self.delegate viewPager:self valueForOption:ViewPagerOptionInitialIndex withDefault:value]; + self.initialIndex = [NSNumber numberWithFloat:value]; } - return _startFromSecondTab; + return _initialIndex; } - (NSNumber *)centerCurrentTab { @@ -560,7 +562,7 @@ - (void)reloadData { _tabOffset = nil; _tabWidth = nil; _tabLocation = nil; - _startFromSecondTab = nil; + _initialIndex = nil; _centerCurrentTab = nil; _fixFormerTabsPositions = nil; _fixLatterTabsPositions = nil; @@ -731,8 +733,8 @@ - (CGFloat)valueForOption:(ViewPagerOption)option { return [[self tabWidth] floatValue]; case ViewPagerOptionTabLocation: return [[self tabLocation] floatValue]; - case ViewPagerOptionStartFromSecondTab: - return [[self startFromSecondTab] floatValue]; + case ViewPagerOptionInitialIndex: + return [[self initialIndex] floatValue]; case ViewPagerOptionCenterCurrentTab: return [[self centerCurrentTab] floatValue]; default: @@ -875,7 +877,7 @@ - (void)defaultSetup { } // Select starting tab - NSUInteger index = [self.startFromSecondTab boolValue] ? 1 : 0; + NSUInteger index = [self.initialIndex integerValue]; [self selectTabAtIndex:index didSwipe:NO]; // Set setup done diff --git a/README.md b/README.md index 18466d6..2b7e88a 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ Every option has a default value. So * `ViewPagerOptionTabOffset`: Tab bar's offset from left, defaults to 56.0 * `ViewPagerOptionTabWidth`: Any tab item's width, defaults to 128.0 * `ViewPagerOptionTabLocation`: 1.0: Top, 0.0: Bottom, Defaults to Top - * `ViewPagerOptionStartFromSecondTab`: 1.0: `YES`, 0.0: `NO`, defines if view should appear with the 1st or 2nd tab. Defaults to `NO` + * `ViewPagerOptionInitialIndex`: Defines which tab the pager should open at. Defaults to `0.0` (i.e. the first tab). Should be an integer. * `ViewPagerOptionCenterCurrentTab`: 1.0: `YES`, 0.0: `NO`, defines if tabs should be centered, with the given tabWidth. Defaults to `NO` * `ViewPagerOptionFixFormerTabsPositions`: 1.0: `YES`, 0.0: `NO`, defines if the active tab should be placed margined by the offset amount to the left. Effects only the former tabs. If set 1.0 (`YES`), first tab will be placed at the same position with the second one, leaving space before itself. Defaults to `NO` * `ViewPagerOptionFixLatterTabsPositions`: 1.0: `YES`, 0.0: `NO`, like `ViewPagerOptionFixFormerTabsPositions`, but effects the latter tabs, making them leave space after themselves. Defaults to `NO`