Skip to content

Commit

Permalink
Merge pull request #9 from mirego/fix/ScrollToIndex_previous_button_i…
Browse files Browse the repository at this point in the history
…ndex_larger_than_button_count

ScrollToIndex: fix when previousButton index is larger than current button count
  • Loading branch information
mbaron authored Jun 14, 2016
2 parents 46f701d + 4dac33b commit 1cdb81f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Pod/Classes/MRGPagerTitleStrip.m
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ - (void)scrollToIndex:(CGFloat)index animated:(BOOL)animated {

if ([self.buttons count] > 0 && (self.scrollView.contentSize.width > CGRectGetWidth(self.scrollView.bounds))) {
CGFloat offset = 0;
NSInteger prevButtonIndex = MAX(floorf(index), 0);
NSInteger prevButtonIndex = MAX(MIN(floorf(index), [self.buttons count]), 0);
NSInteger nextButtonIndex = MIN(ceilf(index), [self.buttons count] - 1);

for (NSInteger ii = 0, count = MIN(prevButtonIndex, [self.buttons count]); ii < count; ++ii) {
for (NSInteger ii = 0, count = prevButtonIndex; ii < count; ++ii) {
offset += CGRectGetWidth([self.buttons[ii] bounds]);
offset += self.separatorSize.width;
}
Expand Down

0 comments on commit 1cdb81f

Please sign in to comment.