forked from erichoracek/MSCollectionViewCalendarLayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSEventCell.m
More file actions
157 lines (129 loc) · 5.23 KB
/
Copy pathMSEventCell.m
File metadata and controls
157 lines (129 loc) · 5.23 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//
// MSEventCell.m
// Example
//
// Created by Eric Horacek on 2/26/13.
// Copyright (c) 2013 Monospace Ltd. All rights reserved.
//
#import "MSEventCell.h"
#import "MSEvent.h"
@interface MSEventCell ()
@property (nonatomic, strong) UIView *borderView;
@end
@implementation MSEventCell
#pragma mark - UIView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.layer.rasterizationScale = [[UIScreen mainScreen] scale];
self.layer.shouldRasterize = YES;
self.layer.shadowColor = [[UIColor blackColor] CGColor];
self.layer.shadowOffset = CGSizeMake(0.0, 4.0);
self.layer.shadowRadius = 5.0;
self.layer.shadowOpacity = 0.0;
self.borderView = [UIView new];
[self.contentView addSubview:self.borderView];
self.title = [UILabel new];
self.title.numberOfLines = 0;
self.title.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.title];
self.location = [UILabel new];
self.location.numberOfLines = 0;
self.location.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.location];
[self updateColors];
CGFloat borderWidth = 2.0;
CGFloat contentMargin = 2.0;
UIEdgeInsets contentPadding = UIEdgeInsetsMake(1.0, (borderWidth + 4.0), 1.0, 4.0);
[self.borderView makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(self.height);
make.width.equalTo(@(borderWidth));
make.left.equalTo(self.left);
make.top.equalTo(self.top);
}];
[self.title makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.top).offset(contentPadding.top);
make.left.equalTo(self.left).offset(contentPadding.left);
make.right.equalTo(self.right).offset(-contentPadding.right);
}];
[self.location makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.title.bottom).offset(contentMargin);
make.left.equalTo(self.left).offset(contentPadding.left);
make.right.equalTo(self.right).offset(-contentPadding.right);
make.bottom.lessThanOrEqualTo(self.bottom).offset(-contentPadding.bottom);
}];
}
return self;
}
#pragma mark - UICollectionViewCell
- (void)setSelected:(BOOL)selected
{
if (selected && (self.selected != selected)) {
[UIView animateWithDuration:0.1 animations:^{
self.transform = CGAffineTransformMakeScale(1.025, 1.025);
self.layer.shadowOpacity = 0.2;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 animations:^{
self.transform = CGAffineTransformIdentity;
}];
}];
} else if (selected) {
self.layer.shadowOpacity = 0.2;
} else {
self.layer.shadowOpacity = 0.0;
}
[super setSelected:selected]; // Must be here for animation to fire
[self updateColors];
}
#pragma mark - MSEventCell
- (void)setEvent:(MSEvent *)event
{
_event = event;
self.title.attributedText = [[NSAttributedString alloc] initWithString:event.title attributes:[self titleAttributesHighlighted:self.selected]];
self.location.attributedText = [[NSAttributedString alloc] initWithString:event.location attributes:[self subtitleAttributesHighlighted:self.selected]];;
}
- (void)updateColors
{
self.contentView.backgroundColor = [self backgroundColorHighlighted:self.selected];
self.borderView.backgroundColor = [self borderColor];
self.title.textColor = [self textColorHighlighted:self.selected];
self.location.textColor = [self textColorHighlighted:self.selected];
}
- (NSDictionary *)titleAttributesHighlighted:(BOOL)highlighted
{
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.alignment = NSTextAlignmentLeft;
paragraphStyle.hyphenationFactor = 1.0;
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
return @{
NSFontAttributeName : [UIFont boldSystemFontOfSize:12.0],
NSForegroundColorAttributeName : [self textColorHighlighted:highlighted],
NSParagraphStyleAttributeName : paragraphStyle
};
}
- (NSDictionary *)subtitleAttributesHighlighted:(BOOL)highlighted
{
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.alignment = NSTextAlignmentLeft;
paragraphStyle.hyphenationFactor = 1.0;
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
return @{
NSFontAttributeName : [UIFont systemFontOfSize:12.0],
NSForegroundColorAttributeName : [self textColorHighlighted:highlighted],
NSParagraphStyleAttributeName : paragraphStyle
};
}
- (UIColor *)backgroundColorHighlighted:(BOOL)selected
{
return selected ? [UIColor colorWithHexString:@"35b1f1"] : [[UIColor colorWithHexString:@"35b1f1"] colorWithAlphaComponent:0.2];
}
- (UIColor *)textColorHighlighted:(BOOL)selected
{
return selected ? [UIColor whiteColor] : [UIColor colorWithHexString:@"21729c"];
}
- (UIColor *)borderColor
{
return [[self backgroundColorHighlighted:NO] colorWithAlphaComponent:1.0];
}
@end