PGDatePickerView.m
1.5 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
//
// PGDatePickerView.m
//
// Created by piggybear on 2017/7/25.
// Copyright © 2017年 piggybear. All rights reserved.
//
#import "PGDatePickerView.h"
#import "UIColor+PGHex.h"
@interface PGDatePickerView()
@property (nonatomic, weak) UILabel *label;
@end
@implementation PGDatePickerView
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGSize size = [self.content sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17]}];
self.label.frame = (CGRect){{self.contentView.bounds.size.width / 2 - size.width / 2,
self.contentView.bounds.size.height / 2 - size.height / 2}, size};
}
#pragma Setter
- (void)setCurrentDate:(BOOL)currentDate {
_currentDate = currentDate;
if (currentDate) {
self.label.textColor = [UIColor colorWithHexString:@"#FAD9A2"];
}else {
self.label.textColor = [UIColor colorWithHexString:@"#838383"];
}
}
- (void)setContent:(NSString *)content {
_content = content;
self.label.text = content;
}
#pragma Getter
- (UILabel *)label {
if (!_label) {
UILabel *label = [[UILabel alloc]init];
label.font = [UIFont systemFontOfSize:17];
[self.contentView addSubview:label];
_label = label;
}
return _label;
}
@end