Skip to content

Commit

Permalink
implements new option: yOffset. It can be used to set vertical offset…
Browse files Browse the repository at this point in the history
… to tabs and contents from topLayout guide or upper bound.
  • Loading branch information
DZamataev committed Mar 12, 2014
1 parent 1fe2346 commit 4564ce1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ICViewPager/Controller/HostViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ - (CGFloat)viewPager:(ViewPagerController *)viewPager valueForOption:(ViewPagerO
return 1.0;
case ViewPagerOptionFixLatterTabsPositions:
return 1.0;
case ViewPagerOptionYOffset:
return 0.0f;
default:
return value;
}
Expand Down
3 changes: 2 additions & 1 deletion ICViewPager/ICViewPager/ViewPagerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ typedef NS_ENUM(NSUInteger, ViewPagerOption) {
ViewPagerOptionStartFromSecondTab,
ViewPagerOptionCenterCurrentTab,
ViewPagerOptionFixFormerTabsPositions,
ViewPagerOptionFixLatterTabsPositions
ViewPagerOptionFixLatterTabsPositions,
ViewPagerOptionYOffset
};

/**
Expand Down
10 changes: 8 additions & 2 deletions ICViewPager/ICViewPager/ViewPagerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define kCenterCurrentTab 0.0
#define kFixFormerTabsPositions 0.0
#define kFixLatterTabsPositions 0.0
#define kYOffset 0.0

#define kIndicatorColor [UIColor colorWithRed:178.0/255.0 green:203.0/255.0 blue:57.0/255.0 alpha:0.75]
#define kTabsViewBackgroundColor [UIColor colorWithRed:234.0/255.0 green:234.0/255.0 blue:234.0/255.0 alpha:0.75]
Expand Down Expand Up @@ -210,16 +211,21 @@ - (void)layoutSubviews {
}
}

CGFloat yOffset = kYOffset;
if ([self.delegate respondsToSelector:@selector(viewPager:valueForOption:withDefault:)]) {
yOffset = [self.delegate viewPager:self valueForOption:ViewPagerOptionYOffset withDefault:yOffset];
}

CGRect frame = self.tabsView.frame;
frame.origin.x = 0.0;
frame.origin.y = [self.tabLocation boolValue] ? topLayoutGuide : CGRectGetHeight(self.view.frame) - [self.tabHeight floatValue];
frame.origin.y = (yOffset) + ([self.tabLocation boolValue] ? topLayoutGuide : CGRectGetHeight(self.view.frame) - [self.tabHeight floatValue]);
frame.size.width = CGRectGetWidth(self.view.frame);
frame.size.height = [self.tabHeight floatValue];
self.tabsView.frame = frame;

frame = self.contentView.frame;
frame.origin.x = 0.0;
frame.origin.y = [self.tabLocation boolValue] ? topLayoutGuide + CGRectGetHeight(self.tabsView.frame) : topLayoutGuide;
frame.origin.y = (yOffset) + ([self.tabLocation boolValue] ? topLayoutGuide + CGRectGetHeight(self.tabsView.frame) : topLayoutGuide);
frame.size.width = CGRectGetWidth(self.view.frame);
frame.size.height = CGRectGetHeight(self.view.frame) - (topLayoutGuide + CGRectGetHeight(self.tabsView.frame)) - CGRectGetHeight(self.tabBarController.tabBar.frame);
self.contentView.frame = frame;
Expand Down

1 comment on commit 4564ce1

@shivanraptor
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very useful, thanks. Hope it can merged with original ICViewPager.

Please sign in to comment.