Skip to content

Commit

Permalink
Add -centerForDate: and -frameForDate:
Browse files Browse the repository at this point in the history
Better for a popover
  • Loading branch information
WenchaoD committed Apr 24, 2016
1 parent 21442ad commit bc3ce07
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
9 changes: 2 additions & 7 deletions Example/StoryboardExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ - (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar
return [calendar dateWithYear:2039 month:5 day:31];
}


- (void)calendar:(FSCalendar *)calendar didDeselectDate:(NSDate *)date
{
NSLog(@"Did deselect date %@",[calendar stringFromDate:date]);
}

#pragma mark - FSCalendarDelegate

- (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date
Expand All @@ -118,7 +112,8 @@ - (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
{
NSLog(@"did select date %@",[calendar stringFromDate:date format:@"yyyy/MM/dd"]);

CGRect frame = [self.calendar frameForDate:date];
NSLog(@"%@",NSStringFromCGRect(frame));
}

- (void)calendarCurrentPageDidChange:(FSCalendar *)calendar
Expand Down
16 changes: 15 additions & 1 deletion FSCalendar/FSCalendar.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,27 @@ IB_DESIGNABLE
- (void)deselectDate:(NSDate *)date;

/**
* Change the current page of the calendar.
* Changes the current page of the calendar.
*
* @param currentPage Representing weekOfYear in week mode, or month in month mode.
* @param animated YES if you want to animate the change in position; NO if it should be immediate.
*/
- (void)setCurrentPage:(NSDate *)currentPage animated:(BOOL)animated;

/**
* Returns the frame for a non-placeholder cell relative to the super view of the calendar.
*
* @param date A date is the calendar.
*/
- (CGRect)frameForDate:(NSDate *)date;

/**
* Returns the midpoint for a non-placeholder cell relative to the super view of the calendar.
*
* @param date A date is the calendar.
*/
- (CGPoint)centerForDate:(NSDate *)date;

@end

#pragma mark - DateTools
Expand Down
19 changes: 19 additions & 0 deletions FSCalendar/FSCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,25 @@ - (void)setCurrentPage:(NSDate *)currentPage animated:(BOOL)animated
}
}

- (CGRect)frameForDate:(NSDate *)date
{
if (!self.superview) {
return CGRectZero;
}
CGRect frame = [_collectionViewLayout layoutAttributesForItemAtIndexPath:[self indexPathForDate:date]].frame;
frame = [self.superview convertRect:frame fromView:_collectionView];
return frame;
}

- (CGPoint)centerForDate:(NSDate *)date
{
CGRect frame = [self frameForDate:date];
if (CGRectIsEmpty(frame)) {
return CGPointZero;
}
return CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame));
}

- (void)setHeaderHeight:(CGFloat)headerHeight
{
if (_headerHeight != headerHeight) {
Expand Down

0 comments on commit bc3ce07

Please sign in to comment.