-
Notifications
You must be signed in to change notification settings - Fork 0
/
JTCalendarAppearance.m
executable file
·140 lines (106 loc) · 4.6 KB
/
JTCalendarAppearance.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// JTCalendarAppearance.m
// JTCalendar
//
// Created by Jonathan Tribouharet
//
#import "JTCalendarAppearance.h"
#import "JTCalendar.h"
@implementation JTCalendarAppearance
- (instancetype)init
{
self = [super init];
if(!self){
return nil;
}
[self setDefaultValues];
return self;
}
- (void)setDefaultValues
{
self.isWeekMode = NO;
// self.weekDayFormat = JTCalendarWeekDayFormatShort;
self.weekDayFormat = JTCalendarWeekDayFormatSingle;
self.useCacheSystem = YES;
self.focusSelectedDayChangeMode = NO;
self.ratioContentMenu = 2.;
self.autoChangeMonth = YES;
self.dayCircleRatio = 1.;
self.dayDotRatio = 1. / 9.;
self.menuMonthTextFont = [UIFont systemFontOfSize:17.];
self.weekDayTextFont = [UIFont systemFontOfSize:14.0];
self.dayTextFont = [UIFont systemFontOfSize:[UIFont systemFontSize]];
self.dayFormat = @"dd";
// Day Background and Border
self.dayBackgroundColor = [UIColor clearColor];
self.dayBorderWidth = 0.0f;
self.dayBorderColor = [UIColor clearColor];
self.menuMonthTextColor = [UIColor blackColor];
// self.weekDayTextColor = [UIColor colorWithRed:152./256. green:147./256. blue:157./256. alpha:1.];
self.weekDayTextColor = [UIColor colorWithRed:48.0f/255.0f green:49.0f/255.0f blue:51.0f/255.0f alpha:1];
[self setDayDotColorForAll:[UIColor colorWithRed:238.0f/255.0f green:102.0f/255.0f blue:55.0f/255.0f alpha:1]];
[self setDayTextColorForAll:[UIColor colorWithRed:48.0f/255.0f green:49.0f/255.0f blue:51.0f/255.0f alpha:1]];
self.dayTextColorOtherMonth = [UIColor colorWithRed:152./256. green:147./256. blue:157./256. alpha:1.];
// self.dayCircleColorSelected = [UIColor redColor];
// self.dayCircleColorSelected = [UIColor colorWithRed:0x33/256. green:0xB3/256. blue:0xEC/256. alpha:.5];
self.dayCircleColorSelected = [UIColor colorWithRed:51.0f/255.0f green:194.0f/255.0f blue:213.0f/255.0f alpha:1];
self.dayTextColorSelected = [UIColor whiteColor];
self.dayDotColorSelected = [UIColor whiteColor];
self.dayCircleColorSelectedOtherMonth = self.dayCircleColorSelected;
self.dayTextColorSelectedOtherMonth = self.dayTextColorSelected;
self.dayDotColorSelectedOtherMonth = self.dayDotColorSelected;
// self.dayCircleColorToday = [UIColor colorWithRed:0x33/256. green:0xB3/256. blue:0xEC/256. alpha:.5];
self.dayCircleColorToday = [UIColor colorWithRed:248.0f/255.0f green:175.0f/255.0f blue:63.0f/255.0f alpha:1];
self.dayTextColorToday = [UIColor whiteColor];
self.dayDotColorToday = [UIColor whiteColor];
self.dayCircleColorTodayOtherMonth = self.dayCircleColorToday;
self.dayTextColorTodayOtherMonth = self.dayTextColorToday;
self.dayDotColorTodayOtherMonth = self.dayDotColorToday;
self.monthBlock = ^NSString *(NSDate *date, JTCalendar *jt_calendar){
NSCalendar *calendar = jt_calendar.calendarAppearance.calendar;
NSDateComponents *comps = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth fromDate:date];
NSInteger currentMonthIndex = comps.month;
static NSDateFormatter *dateFormatter;
if(!dateFormatter){
dateFormatter = [NSDateFormatter new];
dateFormatter.timeZone = jt_calendar.calendarAppearance.calendar.timeZone;
}
while(currentMonthIndex <= 0){
currentMonthIndex += 12;
}
return [[dateFormatter standaloneMonthSymbols][currentMonthIndex - 1] capitalizedString];
};
}
- (NSCalendar *)calendar
{
static NSCalendar *calendar;
static dispatch_once_t once;
dispatch_once(&once, ^{
#ifdef __IPHONE_8_0
calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
#else
calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
#endif
calendar.timeZone = [NSTimeZone localTimeZone];
});
return calendar;
}
- (void)setDayDotColorForAll:(UIColor *)dotColor
{
self.dayDotColor = dotColor;
self.dayDotColorSelected = dotColor;
self.dayDotColorOtherMonth = dotColor;
self.dayDotColorSelectedOtherMonth = dotColor;
self.dayDotColorToday = dotColor;
self.dayDotColorTodayOtherMonth = dotColor;
}
- (void)setDayTextColorForAll:(UIColor *)textColor
{
self.dayTextColor = textColor;
self.dayTextColorSelected = textColor;
self.dayTextColorOtherMonth = textColor;
self.dayTextColorSelectedOtherMonth = textColor;
self.dayTextColorToday = textColor;
self.dayTextColorTodayOtherMonth = textColor;
}
@end