year added to section
This commit is contained in:
parent
b75703ba9a
commit
32731c4b61
|
|
@ -202,10 +202,11 @@ static const CGFloat kSectionHeaderHeight = 56.f;
|
|||
|
||||
TUCalendarMonthSectionView *monthSectionView = [TUCalendarMonthSectionView new];
|
||||
NSInteger currentMonth = [self.calendar component:NSCalendarUnitMonth fromDate:_today];
|
||||
NSInteger currentYear = [self.calendar component:NSCalendarUnitYear fromDate:_today];
|
||||
NSInteger sectionMonthIndex = (currentMonth + i - 1) % _numberOfMonthsInYear;
|
||||
|
||||
monthSectionView.calendar = self.calendar;
|
||||
monthSectionView.monthIndex = (NSUInteger) sectionMonthIndex;
|
||||
[monthSectionView setDateWithMonthIndex:sectionMonthIndex andYear: currentYear];
|
||||
|
||||
mutablePreloadedMonthViews[i] = monthSectionView;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
@property (nonatomic, nullable) NSArray<NSString *> *weekdaysNames;
|
||||
@property (nonatomic, nonnull) NSArray<UIColor *> *weekdaysColors;
|
||||
|
||||
@property (nonatomic) BOOL showYear;
|
||||
|
||||
@end
|
||||
|
||||
@interface TUCalendarMonthSectionView : UIView
|
||||
|
|
@ -30,6 +32,6 @@
|
|||
|
||||
@property (nonatomic, nonnull) NSCalendar *calendar;
|
||||
|
||||
- (void)setMonthIndex:(NSUInteger)monthIndex;
|
||||
- (void)setDateWithMonthIndex:(NSUInteger)monthIndex andYear:(NSUInteger)year;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ static CGFloat const kDayLabelHeight = 14.f;
|
|||
];
|
||||
|
||||
self.dividerColor = [UIColor colorWithHex:0x7B95AA];
|
||||
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
self.showYear = NO;
|
||||
}
|
||||
|
||||
return self;
|
||||
|
|
@ -54,7 +54,7 @@ static CGFloat const kDayLabelHeight = 14.f;
|
|||
|
||||
@interface TUCalendarMonthSectionView ()
|
||||
|
||||
@property (strong, nonatomic) UILabel *monthNameLabel;
|
||||
@property (strong, nonatomic) UILabel *sectionTitleLabel;
|
||||
@property (strong, nonatomic) NSArray<UILabel *> *daysLabels;
|
||||
@property (strong, nonatomic) UIView *divider;
|
||||
|
||||
|
|
@ -73,10 +73,10 @@ static CGFloat const kDayLabelHeight = 14.f;
|
|||
}
|
||||
|
||||
- (void)setupViews {
|
||||
UILabel *monthNameLabel = [UILabel new];
|
||||
monthNameLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self addSubview:monthNameLabel];
|
||||
self.monthNameLabel = monthNameLabel;
|
||||
UILabel *sectionTitleLabel = [UILabel new];
|
||||
sectionTitleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self addSubview:sectionTitleLabel];
|
||||
self.sectionTitleLabel = sectionTitleLabel;
|
||||
|
||||
NSMutableArray<UILabel *> *daysLabels = [NSMutableArray arrayWithCapacity:kNumberOfDaysInWeek];
|
||||
|
||||
|
|
@ -102,28 +102,35 @@ static CGFloat const kDayLabelHeight = 14.f;
|
|||
CGFloat width = self.frame.size.width;
|
||||
CGFloat height = self.frame.size.height;
|
||||
|
||||
self.monthNameLabel.frame = CGRectMake(0.f, kMonthLabelTopToSuperviewSpace, width, kMonthLabelHeight);
|
||||
self.sectionTitleLabel.frame = CGRectMake(0.f, kMonthLabelTopToSuperviewSpace, width, kMonthLabelHeight);
|
||||
|
||||
CGFloat dividerHeight = 0.5f;
|
||||
self.divider.frame = CGRectMake(0.f, height - dividerHeight, width, dividerHeight);
|
||||
|
||||
CGFloat daysY = CGRectGetMaxY(self.monthNameLabel.frame) + kDaysToMonthVerticalSpace;
|
||||
CGFloat daysY = CGRectGetMaxY(self.sectionTitleLabel.frame) + kDaysToMonthVerticalSpace;
|
||||
CGFloat dayViewWidth = (width - 2 * kDaysLabelsLeftRightInset) / kNumberOfDaysInWeek;
|
||||
[self.daysLabels enumerateObjectsUsingBlock:^(UILabel * _Nonnull dayLabel, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
dayLabel.frame = CGRectMake(kDaysLabelsLeftRightInset + dayViewWidth * idx, daysY, dayViewWidth, kDayLabelHeight);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setMonthIndex:(NSUInteger)monthIndex {
|
||||
- (void)setDateWithMonthIndex:(NSUInteger)monthIndex andYear:(NSUInteger)year; {
|
||||
NSString *monthName = self.calendar.standaloneMonthSymbols[monthIndex];
|
||||
self.monthNameLabel.text = [monthName capitalizedString];
|
||||
|
||||
NSString *sectionTitle = monthName;
|
||||
|
||||
if (_monthSectionAppearance.showYear) {
|
||||
[sectionTitle stringByAppendingString:[NSString stringWithFormat:@" %lu", (unsigned long)year]];
|
||||
}
|
||||
|
||||
self.sectionTitleLabel.text = [sectionTitle capitalizedString];
|
||||
}
|
||||
|
||||
- (void)setMonthSectionAppearance:(TUCalendarMonthSectionViewAppearance *)monthSectionAppearance {
|
||||
_monthSectionAppearance = monthSectionAppearance;
|
||||
|
||||
self.monthNameLabel.font = self.monthSectionAppearance.titleFont;
|
||||
self.monthNameLabel.textColor = self.monthSectionAppearance.titleColor;
|
||||
self.sectionTitleLabel.font = self.monthSectionAppearance.titleFont;
|
||||
self.sectionTitleLabel.textColor = self.monthSectionAppearance.titleColor;
|
||||
|
||||
for (NSUInteger i = 0; i < kNumberOfDaysInWeek; ++i) {
|
||||
UILabel *dayLabel = self.daysLabels[i];
|
||||
|
|
|
|||
Loading…
Reference in New Issue