Skip to content

Commit

Permalink
[Sources] [DatePickerView+Protected] Add `dateForFirstDayInCurrentSec…
Browse files Browse the repository at this point in the history
…tion`.

#126, #133, #135
  • Loading branch information
ruslanskorb committed Mar 24, 2018
1 parent d5c1298 commit 671970a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions RSDayFlow/RSDFDatePickerView+Protected.h
Expand Up @@ -34,6 +34,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface RSDFDatePickerView (RSDFDatePickerViewProtectedMethods)

/**
The date of the first day of the month that corresponds to the currently visible section in the date picker view.
*/
@property (nonatomic, readonly, nullable) NSDate *dateForFirstDayInCurrentSection;

/**
Returns the date that corresponds to the specified cell in the date picker view.
Expand Down
26 changes: 26 additions & 0 deletions RSDayFlow/RSDFDatePickerView.m
Expand Up @@ -194,6 +194,32 @@ - (Class)collectionViewLayoutClass
return [RSDFDatePickerCollectionViewLayout class];
}

- (NSDate *)dateForFirstDayInCurrentSection
{
CGPoint point = [self.collectionView.superview convertPoint:self.collectionView.center toView:self.collectionView];
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:point];
if (indexPath == nil) {

NSArray<UICollectionViewLayoutAttributes *> *layoutAttributesArray = [self.collectionView.collectionViewLayout layoutAttributesForElementsInRect:self.collectionView.bounds];
if (layoutAttributesArray.count == 0) {

return nil;
}

for (UICollectionViewLayoutAttributes *layoutAttributes in layoutAttributesArray) {

if (CGRectContainsPoint(layoutAttributes.frame, point) == YES) {

return [self dateForFirstDayInSection:layoutAttributes.indexPath.section];
}
}

return nil;
}

return [self dateForFirstDayInSection:indexPath.section];
}

- (Class)dayCellClass
{
return [RSDFDatePickerDayCell class];
Expand Down

0 comments on commit 671970a

Please sign in to comment.