diff --git a/Example/StoryboardExampleViewController.m b/Example/StoryboardExampleViewController.m index 4daae73..0dca6de 100644 --- a/Example/StoryboardExampleViewController.m +++ b/Example/StoryboardExampleViewController.m @@ -68,6 +68,11 @@ #pragma mark - FSCalendarDataSource +- (NSString *)calendar:(FSCalendar *)calendar titleForDate:(NSDate *)date +{ + return [calendar isDateInToday:date] ? @"今天" : nil; +} + - (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date { if (!_lunar) { diff --git a/FSCalendar/FSCalendar.h b/FSCalendar/FSCalendar.h index 1b821d1..ba6c61f 100644 --- a/FSCalendar/FSCalendar.h +++ b/FSCalendar/FSCalendar.h @@ -56,6 +56,11 @@ NS_ASSUME_NONNULL_BEGIN @optional +/** + * Asks the dataSource for a title for the specific date as a replacement of the day text + */ +- (nullable NSString *)calendar:(FSCalendar *)calendar titleForDate:(NSDate *)date; + /** * Asks the dataSource for a subtitle for the specific date under the day text. */ diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index 07e86c9..bef5f02 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -26,6 +26,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) { @interface FSCalendar (DataSourceAndDelegate) - (NSInteger)numberOfEventsForDate:(NSDate *)date; +- (NSString *)titleForDate:(NSDate *)date; - (NSString *)subtitleForDate:(NSDate *)date; - (UIImage *)imageForDate:(NSDate *)date; - (NSDate *)minimumDateForCalendar; @@ -1577,6 +1578,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) { cell.date = [self dateForIndexPath:indexPath]; cell.image = [self imageForDate:cell.date]; cell.numberOfEvents = [self numberOfEventsForDate:cell.date]; + cell.title = [self titleForDate:cell.date]; cell.subtitle = [self subtitleForDate:cell.date]; cell.dateIsSelected = [_selectedDates containsObject:cell.date]; cell.dateIsToday = [self isDateInToday:cell.date]; @@ -1893,6 +1895,18 @@ typedef NS_ENUM(NSUInteger, FSCalendarOrientation) { #pragma mark - DataSource +- (NSString *)titleForDate:(NSDate *)date +{ +#if !TARGET_INTERFACE_BUILDER + if (_dataSource && [_dataSource respondsToSelector:@selector(calendar:titleForDate:)]) { + return [_dataSource calendar:self titleForDate:date]; + } + return nil; +#else + return _appearance.fakeSubtitles ? @"test" : nil; +#endif +} + - (NSString *)subtitleForDate:(NSDate *)date { #if !TARGET_INTERFACE_BUILDER diff --git a/FSCalendar/FSCalendarCell.h b/FSCalendar/FSCalendarCell.h index 01d303e..3a8a2cc 100644 --- a/FSCalendar/FSCalendarCell.h +++ b/FSCalendar/FSCalendarCell.h @@ -23,6 +23,7 @@ @property (weak, nonatomic) FSCalendarEventIndicator *eventIndicator; @property (strong, nonatomic) NSDate *date; +@property (strong, nonatomic) NSString *title; @property (strong, nonatomic) NSString *subtitle; @property (strong, nonatomic) UIImage *image; diff --git a/FSCalendar/FSCalendarCell.m b/FSCalendar/FSCalendarCell.m index 90f5567..72db231 100644 --- a/FSCalendar/FSCalendarCell.m +++ b/FSCalendar/FSCalendarCell.m @@ -141,7 +141,7 @@ if (self.contentView.hidden) { return; } - _titleLabel.text = [NSString stringWithFormat:@"%@",@([_calendar dayOfDate:_date])]; + _titleLabel.text = self.title ?: [NSString stringWithFormat:@"%@",@([_calendar dayOfDate:_date])]; if (_subtitle) { _subtitleLabel.text = _subtitle; if (_subtitleLabel.hidden) {