jivesoftware / PDTSimpleCalendar

A simple Calendar / Date Picker for iOS using UICollectionView

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom calendar view cell size.

markst opened this issue · comments

I'm subclassing PDTSimpleCalendarViewController so that I can use a custom cell size.
Which works fine:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat itemWidth = floorf(CGRectGetWidth(self.collectionView.bounds) / self.daysPerWeek);
    return CGSizeMake(itemWidth, 35.0);
}

However this causes issues when scrolling to date: scrollToDate:
Since the y origin in calculated:
origin.y -= (PDTSimpleCalendarFlowLayoutHeaderHeight + PDTSimpleCalendarFlowLayoutInsetTop + self.collectionView.contentInset.top);

commented

What's happening?
Can you post a screenshot?

From what I see you only specify a fixed height. This shouldn't interfere with the scrollToDate method.

ah so the issue is because I'm using a smaller size calendar view (90 pt high) which means the entire height of the calendar month doesn't fit.

A resolution for this is in the method scrollToDate:
Rather than scrolling to the date month section, scrolling to the exact index path works:

UICollectionViewLayoutAttributes *sectionLayoutAttributes = [self.collectionView layoutAttributesForItemAtIndexPath:selectedDateIndexPath];