在iOS中自定义JTCalender中的颜色?

时间:2016-12-05 07:30:43

标签: ios jtcalendar

我在iOS中使用JTCalender。我想在同一颜色中制作日期,月份等标签的颜色。截至目前,某些日期它是黑色的。

enter image description here

请建议我如何实现这一目标?

1 个答案:

答案 0 :(得分:2)

您可以使用JTCalendar委托方法

自定义日视图
- (UIView<JTCalendarDay> *)calendarBuildDayView:(JTCalendarManager *)calendar
{
    JTCalendarDayView *view = [JTCalendarDayView new];
    view.textLabel.font = [UIFont fontWithName:@"Avenir-Light" size:13];
    view.textLabel.textColor = [UIColor blackColor];

    return view;
}
- (void)calendar:(JTCalendarManager *)calendar prepareDayView:(JTCalendarDayView *)dayView
{
    dayView.hidden = NO;

    // Test if the dayView is from another month than the page
    // Use only in month mode for indicate the day of the previous or next month
    if([dayView isFromAnotherMonth]){ 
        dayView.hidden = YES;
    }
    // Today
    else if([_calendarManager.dateHelper date:[NSDate date] isTheSameDayThan:dayView.date]){
        dayView.circleView.hidden = NO;
        dayView.circleView.backgroundColor = [UIColor blueColor];
        dayView.dotView.backgroundColor = [UIColor whiteColor];
        dayView.textLabel.textColor = [UIColor whiteColor];
    }
    // Selected date
    else if(_dateSelected && [_calendarManager.dateHelper date:_dateSelected isTheSameDayThan:dayView.date]){
        dayView.circleView.hidden = NO;
        dayView.circleView.backgroundColor = [UIColor redColor];
        dayView.dotView.backgroundColor = [UIColor whiteColor];
        dayView.textLabel.textColor = [UIColor whiteColor];
    }
    // Another day of the current month
    else{
        dayView.circleView.hidden = YES;
        dayView.dotView.backgroundColor = [UIColor redColor];
        dayView.textLabel.textColor = [UIColor blackColor];
    }

    // Your method to test if a date have an event for example
    if([self haveEventForDay:dayView.date]){
        dayView.dotView.hidden = NO;
    }
    else{
        dayView.dotView.hidden = YES;
    }
}

注意:代码在Objective C中,请使用Swift中的相应方法。

来源:https://github.com/jonathantribouharet/JTCalendar

编辑:(按照Kglay Kophyo的建议) 您可以在委托中更改月份的颜色。

- (UIView *)calendarBuildMenuItemView:(JTCalendarManager *)calendar 
{ 
   UILabel *label = [UILabel new]; 
   label.textColor = [UIColor redColor]; // your color return label; 
}