diff --git a/TUCalendar/TUCalendar/Controllers/TUCalendarViewController.m b/TUCalendar/TUCalendar/Controllers/TUCalendarViewController.m index f3019f2..8756c96 100644 --- a/TUCalendar/TUCalendar/Controllers/TUCalendarViewController.m +++ b/TUCalendar/TUCalendar/Controllers/TUCalendarViewController.m @@ -18,8 +18,6 @@ static const NSInteger kNumberOfDaysInWeek = 7; -static const CGFloat kSectionHeaderHeight = 56.f; - @interface TUCalendarViewController () { NSMutableDictionary *_calculatedSettings; @@ -276,7 +274,7 @@ static const CGFloat kSectionHeaderHeight = 56.f; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { - return kSectionHeaderHeight; + return [TUCalendarMonthSectionView appearance].monthSectionAppearance.sectionHeaderHeight; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { diff --git a/TUCalendar/TUCalendar/Views/SectionsViews/TUCalendarMonthSectionView.h b/TUCalendar/TUCalendar/Views/SectionsViews/TUCalendarMonthSectionView.h index b55060d..2740c4f 100644 --- a/TUCalendar/TUCalendar/Views/SectionsViews/TUCalendarMonthSectionView.h +++ b/TUCalendar/TUCalendar/Views/SectionsViews/TUCalendarMonthSectionView.h @@ -23,6 +23,13 @@ @property (nonatomic, nonnull) NSArray *weekdaysColors; @property (nonatomic) BOOL showYear; +@property (nonatomic) BOOL showWeekDays; + +@property (nonatomic) UIEdgeInsets alignmentTitleLabelRectInsets; +@property (nonatomic) NSTextAlignment titleLabelTextAlignment; +@property (nonatomic) BOOL showDevider; + +@property (nonatomic) CGFloat sectionHeaderHeight; @end diff --git a/TUCalendar/TUCalendar/Views/SectionsViews/TUCalendarMonthSectionView.m b/TUCalendar/TUCalendar/Views/SectionsViews/TUCalendarMonthSectionView.m index 4ca9701..0d23a3f 100644 --- a/TUCalendar/TUCalendar/Views/SectionsViews/TUCalendarMonthSectionView.m +++ b/TUCalendar/TUCalendar/Views/SectionsViews/TUCalendarMonthSectionView.m @@ -16,6 +16,7 @@ static CGFloat const kMonthLabelHeight = 18.f; static CGFloat const kDaysToMonthVerticalSpace = 10.f; static CGFloat const kDaysLabelsLeftRightInset = 6.f; static CGFloat const kDayLabelHeight = 14.f; +static CGFloat const kSectionHeaderHeight = 56.f; @implementation TUCalendarMonthSectionViewAppearance @@ -44,6 +45,13 @@ static CGFloat const kDayLabelHeight = 14.f; self.dividerColor = [UIColor colorWithHex:0x7B95AA]; self.backgroundColor = [UIColor whiteColor]; self.showYear = NO; + self.showWeekDays = YES; + + self.alignmentTitleLabelRectInsets = UIEdgeInsetsZero; + self.titleLabelTextAlignment = NSTextAlignmentCenter; + self.showDevider = YES; + + self.sectionHeaderHeight = kSectionHeaderHeight; } return self; @@ -77,7 +85,7 @@ static CGFloat const kDayLabelHeight = 14.f; - (void)setupViews { UILabel *sectionTitleLabel = [UILabel new]; - sectionTitleLabel.textAlignment = NSTextAlignmentCenter; + sectionTitleLabel.textAlignment = _monthSectionAppearance.titleLabelTextAlignment; [self addSubview:sectionTitleLabel]; self.sectionTitleLabel = sectionTitleLabel; @@ -104,17 +112,29 @@ static CGFloat const kDayLabelHeight = 14.f; CGFloat width = self.frame.size.width; CGFloat height = self.frame.size.height; - - 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.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); - }]; + + CGRect sectionTitleLabelFrame; + + if (!_monthSectionAppearance.showWeekDays) { + UIEdgeInsets alignmentTitleLabelRectInsets = _monthSectionAppearance.alignmentTitleLabelRectInsets; + sectionTitleLabelFrame = CGRectMake(alignmentTitleLabelRectInsets.left, + alignmentTitleLabelRectInsets.top, + width - alignmentTitleLabelRectInsets.left - alignmentTitleLabelRectInsets.right, + height - alignmentTitleLabelRectInsets.top - alignmentTitleLabelRectInsets.bottom); + } else { + sectionTitleLabelFrame = CGRectMake(0.f, kMonthLabelTopToSuperviewSpace, width, kMonthLabelHeight); + + CGFloat dividerHeight = 0.5f; + self.divider.frame = CGRectMake(0.f, height - dividerHeight, width, dividerHeight); + + 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); + }]; + } + + self.sectionTitleLabel.frame = sectionTitleLabelFrame; } - (void)setDateWithMonthIndex:(NSUInteger)monthIndex andYear:(NSUInteger)year; { @@ -152,8 +172,16 @@ static CGFloat const kDayLabelHeight = 14.f; self.divider.backgroundColor = self.monthSectionAppearance.dividerColor; self.backgroundColor = self.monthSectionAppearance.backgroundColor; + self.sectionTitleLabel.textAlignment = _monthSectionAppearance.titleLabelTextAlignment; + + for (UILabel *weekDay in self.daysLabels) { + weekDay.hidden = !_monthSectionAppearance.showWeekDays; + } + + self.divider.hidden = !_monthSectionAppearance.showDevider; [self setSectionTitle]; + [self layoutSubviews]; } - (void)didMoveToSuperview {