1

I am using JTCalender in iOS.I want to make color of labels such as date,month name in same color.As of now it is black for some dates.

enter image description here

Please suggesst how can i achieve this ?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
TechChain
  • 8,404
  • 29
  • 103
  • 228

1 Answers1

2

You can customize day views by using JTCalendar delegate methods

- (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;
    }
}

Note : The code is in Objective C, please use the respective methods in Swift.

Source : https://github.com/jonathantribouharet/JTCalendar

Edit: (As suggested by Kglay Kophyo) You can change the color of month in delegate .

- (UIView *)calendarBuildMenuItemView:(JTCalendarManager *)calendar 
{ 
   UILabel *label = [UILabel new]; 
   label.textColor = [UIColor redColor]; // your color return label; 
}  
Ravi
  • 2,441
  • 1
  • 11
  • 30