jivesoftware / PDTSimpleCalendar

A simple Calendar / Date Picker for iOS using UICollectionView
Apache License 2.0
1.93k stars 338 forks source link

Custom calendar view cell size. #49

Open markst opened 9 years ago

markst commented 9 years ago

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);

jmig commented 9 years ago

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.

markst commented 9 years ago

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];