diff --git a/ICViewPager.podspec b/ICViewPager.podspec index 3d96184..e8b695c 100644 --- a/ICViewPager.podspec +++ b/ICViewPager.podspec @@ -32,7 +32,7 @@ Pod::Spec.new do |s| s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "Ilter Cengiz" => "me@iltercengiz.info" } s.platform = :ios, '6.0' - s.source = { :git => "https://github.com/monsieurje/ICViewPager.git", :tag => "1.5.1" } + s.source = { :git => "https://github.com/monsieurje/ICViewPager.git", :tag => "1.5.3" } s.source_files = 'ICViewPager/ICViewPager/*.{h,m}' s.requires_arc = true diff --git a/ICViewPager/ICViewPager/ViewPagerController.h b/ICViewPager/ICViewPager/ViewPagerController.h index 6652bfd..409d379 100644 --- a/ICViewPager/ICViewPager/ViewPagerController.h +++ b/ICViewPager/ICViewPager/ViewPagerController.h @@ -25,6 +25,10 @@ typedef NS_ENUM(NSUInteger, ViewPagerOption) { ViewPagerOptionTabOffset, ViewPagerOptionTabWidth, ViewPagerOptionTabLocation, + ViewPagerOptionTabNormalLineWidth, + ViewPagerOptionTabSelectedLineWidth, + ViewPagerOptionTabDisableTopLine, + ViewPagerOptionTabDisableBottomLine, ViewPagerOptionStartFromSecondTab, ViewPagerOptionCenterCurrentTab, ViewPagerOptionFixFormerTabsPositions, @@ -168,6 +172,23 @@ typedef NS_ENUM(NSUInteger, ViewPagerComponent) { * @param index The index of the active tab */ - (void)viewPager:(ViewPagerController *)viewPager didChangeTabToIndex:(NSUInteger)index; +/** + * delegate object should implement this method if it wants to be informed when a tab changes and what its previous tab index was + * + * @param viewPager The viewPager that's subject to + * @param index The index of the active tab + * @param previousIndex The previous index of the active tab + */ +- (void)viewPager:(ViewPagerController *)viewPager didChangeTabToIndex:(NSUInteger)index fromIndex:(NSUInteger)previousIndex; +/** + * delegate object should implement this method if it wants to be informed when a tab changes and what its previous tab index was and whether the change action was caused by a swipe gesture or tab bar button press + * + * @param viewPager The viewPager that's subject to + * @param index The index of the active tab + * @param previousIndex The previous index of the active tab + * @param didSwipe Indicating if the change action was caused by a swipe gesture or a tab bar button press + */ +- (void)viewPager:(ViewPagerController *)viewPager didChangeTabToIndex:(NSUInteger)index fromIndex:(NSUInteger)previousIndex didSwipe:(BOOL)didSwipe; /** * Every time -reloadData method called, ViewPager will ask its delegate for option values. * So you don't have to set options from ViewPager itself. diff --git a/ICViewPager/ICViewPager/ViewPagerController.m b/ICViewPager/ICViewPager/ViewPagerController.m index 4281853..bb29107 100644 --- a/ICViewPager/ICViewPager/ViewPagerController.m +++ b/ICViewPager/ICViewPager/ViewPagerController.m @@ -17,6 +17,10 @@ #define kTabOffset 56.0 #define kTabWidth 128.0 #define kTabLocation 1.0 +#define kTabNormalLineWidth 1.0 +#define kTabSelectedLineWidth 5.0 +#define kTabDisableTopLine 0.0 +#define kTabDisableBottomLine 0.0 #define kStartFromSecondTab 0.0 #define kCenterCurrentTab 0.0 #define kFixFormerTabsPositions 0.0 @@ -62,6 +66,10 @@ - (BOOL)isEqualToColor:(UIColor *)otherColor { @interface TabView : UIView @property (nonatomic, getter = isSelected) BOOL selected; @property (nonatomic) UIColor *indicatorColor; +@property (nonatomic) BOOL disableTopLine; +@property (nonatomic) BOOL disableBottomLine; +@property (nonatomic) CGFloat normalLineWidth; +@property (nonatomic) CGFloat selectedLineWidth; @end @implementation TabView @@ -69,6 +77,8 @@ - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor clearColor]; + self.normalLineWidth = 1.0; + self.selectedLineWidth = 5.0; } return self; } @@ -86,7 +96,7 @@ - (void)drawRect:(CGRect)rect { [bezierPath moveToPoint:CGPointMake(0.0, 0.0)]; [bezierPath addLineToPoint:CGPointMake(CGRectGetWidth(rect), 0.0)]; [[UIColor colorWithWhite:197.0/255.0 alpha:0.75] setStroke]; - [bezierPath setLineWidth:1.0]; + [bezierPath setLineWidth:(self.disableTopLine ? 0.0 : self.normalLineWidth)]; [bezierPath stroke]; // Draw bottom line @@ -94,7 +104,7 @@ - (void)drawRect:(CGRect)rect { [bezierPath moveToPoint:CGPointMake(0.0, CGRectGetHeight(rect))]; [bezierPath addLineToPoint:CGPointMake(CGRectGetWidth(rect), CGRectGetHeight(rect))]; [[UIColor colorWithWhite:197.0/255.0 alpha:0.75] setStroke]; - [bezierPath setLineWidth:1.0]; + [bezierPath setLineWidth:(self.disableBottomLine ? 0.0 : self.normalLineWidth)]; [bezierPath stroke]; // Draw an indicator line if tab is selected @@ -105,7 +115,7 @@ - (void)drawRect:(CGRect)rect { // Draw the indicator [bezierPath moveToPoint:CGPointMake(0.0, CGRectGetHeight(rect) - 1.0)]; [bezierPath addLineToPoint:CGPointMake(CGRectGetWidth(rect), CGRectGetHeight(rect) - 1.0)]; - [bezierPath setLineWidth:5.0]; + [bezierPath setLineWidth:self.selectedLineWidth]; [self.indicatorColor setStroke]; [bezierPath stroke]; } @@ -131,6 +141,10 @@ @interface ViewPagerController () = self.tabCount) { return; @@ -581,6 +676,9 @@ - (void)selectTabAtIndex:(NSUInteger)index { self.animatingToTab = YES; + // Keep a reference to previousIndex in case it is needed for the delegate + NSUInteger previousIndex = self.activeTabIndex; + // Set activeTabIndex self.activeTabIndex = index; @@ -591,6 +689,12 @@ - (void)selectTabAtIndex:(NSUInteger)index { if ([self.delegate respondsToSelector:@selector(viewPager:didChangeTabToIndex:)]) { [self.delegate viewPager:self didChangeTabToIndex:self.activeTabIndex]; } + else if([self.delegate respondsToSelector:@selector(viewPager:didChangeTabToIndex:fromIndex:)]){ + [self.delegate viewPager:self didChangeTabToIndex:self.activeTabIndex fromIndex:previousIndex]; + } + else if ([self.delegate respondsToSelector:@selector(viewPager:didChangeTabToIndex:fromIndex:didSwipe:)]) { + [self.delegate viewPager:self didChangeTabToIndex:self.activeTabIndex fromIndex:previousIndex didSwipe:didSwipe]; + } } - (void)setNeedsReloadOptions { @@ -717,6 +821,14 @@ - (CGFloat)valueForOption:(ViewPagerOption)option { return [[self tabWidth] floatValue]; case ViewPagerOptionTabLocation: return [[self tabLocation] floatValue]; + case ViewPagerOptionTabNormalLineWidth: + return [[self tabNormalLineWidth] floatValue]; + case ViewPagerOptionTabSelectedLineWidth: + return [[self tabSelectedLineWidth] floatValue]; + case ViewPagerOptionTabDisableTopLine: + return [[self tabDisableTopLine] floatValue]; + case ViewPagerOptionTabDisableBottomLine: + return [[self tabDisableBottomLine] floatValue]; case ViewPagerOptionStartFromSecondTab: return [[self startFromSecondTab] floatValue]; case ViewPagerOptionCenterCurrentTab: @@ -747,7 +859,7 @@ - (void)defaultSettings { navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; [self addChildViewController:self.pageViewController]; - + // Setup some forwarding events to hijack the scrollView // Keep a reference to the actual delegate self.actualDelegate = ((UIScrollView *)[self.pageViewController.view.subviews objectAtIndex:0]).delegate; @@ -862,7 +974,7 @@ - (void)defaultSetup { // Select starting tab NSUInteger index = [self.startFromSecondTab boolValue] ? 1 : 0; - [self selectTabAtIndex:index]; + [self selectTabAtIndex:index didSwipe:NO]; // Set setup done self.defaultSetupDone = YES; @@ -875,7 +987,7 @@ - (TabView *)tabViewAtIndex:(NSUInteger)index { } if ([[self.tabs objectAtIndex:index] isEqual:[NSNull null]]) { - + // Get view from dataSource UIView *tabViewContent = [self.dataSource viewPager:self viewForTabAtIndex:index]; tabViewContent.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; @@ -885,6 +997,10 @@ - (TabView *)tabViewAtIndex:(NSUInteger)index { [tabView addSubview:tabViewContent]; [tabView setClipsToBounds:YES]; [tabView setIndicatorColor:self.indicatorColor]; + [tabView setNormalLineWidth:[self.tabNormalLineWidth floatValue]]; + [tabView setSelectedLineWidth:[self.tabSelectedLineWidth floatValue]]; + [tabView setDisableTopLine:[self.tabDisableTopLine boolValue]]; + [tabView setDisableBottomLine:[self.tabDisableBottomLine boolValue]]; tabViewContent.center = tabView.center; @@ -955,7 +1071,7 @@ - (void)pageViewController:(UIPageViewController *)pageViewController didFinishA // Select tab NSUInteger index = [self indexForViewController:viewController]; - [self selectTabAtIndex:index]; + [self selectTabAtIndex:index didSwipe:YES]; } #pragma mark - UIScrollViewDelegate, Responding to Scrolling and Dragging diff --git a/ICViewPager/iPhone.storyboard b/ICViewPager/iPhone.storyboard index e35b3ad..51e5ca7 100644 --- a/ICViewPager/iPhone.storyboard +++ b/ICViewPager/iPhone.storyboard @@ -1,17 +1,21 @@ - + - - - + + + + + + + - + @@ -25,8 +29,12 @@ + + + + - + - - - + + +