forked from WenchaoD/FSCalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DIYCalendarCell.m
83 lines (62 loc) · 3.01 KB
/
DIYCalendarCell.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
//
// DIYCalendarCell.m
// FSCalendar
//
// Created by dingwenchao on 02/11/2016.
// Copyright © 2016 Wenchao Ding. All rights reserved.
//
#import "DIYCalendarCell.h"
#import "FSCalendarExtensions.h"
@implementation DIYCalendarCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
UIImageView *circleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"circle"]];
[self.contentView insertSubview:circleImageView atIndex:0];
self.circleImageView = circleImageView;
CAShapeLayer *selectionLayer = [[CAShapeLayer alloc] init];
selectionLayer.fillColor = [UIColor blackColor].CGColor;
selectionLayer.actions = @{@"hidden":[NSNull null]};
[self.contentView.layer insertSublayer:selectionLayer below:self.titleLabel.layer];
self.selectionLayer = selectionLayer;
self.shapeLayer.hidden = YES;
self.backgroundView = [[UIView alloc] initWithFrame:self.bounds];
self.backgroundView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.1];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.backgroundView.frame = CGRectInset(self.bounds, 1, 1);
self.circleImageView.frame = self.backgroundView.frame;
self.selectionLayer.frame = self.bounds;
if (self.selectionType == SelectionTypeMiddle) {
self.selectionLayer.path = [UIBezierPath bezierPathWithRect:self.selectionLayer.bounds].CGPath;
} else if (self.selectionType == SelectionTypeLeftBorder) {
self.selectionLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.selectionLayer.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerBottomLeft cornerRadii:CGSizeMake(self.selectionLayer.fs_width/2, self.selectionLayer.fs_width/2)].CGPath;
} else if (self.selectionType == SelectionTypeRightBorder) {
self.selectionLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.selectionLayer.bounds byRoundingCorners:UIRectCornerTopRight|UIRectCornerBottomRight cornerRadii:CGSizeMake(self.selectionLayer.fs_width/2, self.selectionLayer.fs_width/2)].CGPath;
} else if (self.selectionType == SelectionTypeSingle) {
CGFloat diameter = MIN(self.selectionLayer.fs_height, self.selectionLayer.fs_width);
self.selectionLayer.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(self.contentView.fs_width/2-diameter/2, self.contentView.fs_height/2-diameter/2, diameter, diameter)].CGPath;
}
}
- (void)configureAppearance
{
[super configureAppearance];
// Override the build-in appearance configuration
if (self.isPlaceholder) {
self.titleLabel.textColor = [UIColor lightGrayColor];
self.eventIndicator.hidden = YES;
}
}
- (void)setSelectionType:(SelectionType)selectionType
{
if (_selectionType != selectionType) {
_selectionType = selectionType;
[self setNeedsLayout];
}
}
@end