AudioDetailHeaderView.m
5.1 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
//
// AudioDetailHeaderView.m
// DreamSleep
//
// Created by peter on 2022/5/6.
//
#import "AudioDetailHeaderView.h"
@interface AudioDetailHeaderView ()
@property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) UIImageView *audioIV;
@property (nonatomic, strong) UILabel *audioNameLab;
@property (nonatomic, strong) UILabel *audioDescLab;
@property (nonatomic, strong) UIView *cornerView;
@end
@implementation AudioDetailHeaderView
- (instancetype)initWithModel:(CourseModel *)model courseType:(CourseType)courseType {
if (self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, courseType == CourseTypeSafe ? 250 : 300)]) {
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.clipsToBounds = YES;
[self addSubview:self.bgIV];
[self addSubview:self.audioIV];
[self addSubview:self.audioNameLab];
if (courseType == CourseTypeSafe) {
[self addSubview:self.audioDescLab];
[self addSubview:self.cornerView];
self.audioDescLab.text = model.audio_desc;
}
[self.bgIV yy_setImageWithURL:[NSURL URLWithString:model.bg_url] placeholder:[UIImage imageNamed:@"bannerPlaceholder"]];
[self.audioIV yy_setImageWithURL:[NSURL URLWithString:model.audio_img] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
self.audioNameLab.text = model.audio_name;
self.audioNameLab.font = courseType == CourseTypeSafe ? BoldFont(16.0) : BoldFont(18.0);
[self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
if (courseType == CourseTypeSafe) {
make.edges.equalTo(self);
} else {
make.top.left.right.equalTo(self);
make.height.equalTo(@210);
}
}];
[self.audioIV mas_makeConstraints:^(MASConstraintMaker *make) {
if (courseType == CourseTypeSafe) {
make.left.equalTo(self).offset(17);
make.top.equalTo(self).offset(105);
make.width.height.equalTo(@100);
} else {
make.centerX.equalTo(self);
make.width.height.equalTo(@118);
make.top.equalTo(self).offset(118);
}
}];
[self.audioNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
if (courseType == CourseTypeSafe) {
make.left.equalTo(self.audioIV.mas_right).offset(30);
make.top.equalTo(self.audioIV);
} else {
make.centerX.equalTo(self);
make.top.equalTo(self.audioIV.mas_bottom).offset(15);
}
}];
if (courseType == CourseTypeSafe) {
[self.audioDescLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.audioNameLab);
make.top.equalTo(self.audioNameLab.mas_bottom).offset(10);
make.right.equalTo(self).offset(-17);
}];
[self.cornerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self);
make.bottom.equalTo(self).offset(20);
make.height.equalTo(@40);
}];
}
// 更新布局
[self layoutIfNeeded];
if (courseType == CourseTypeRelax) {
// 添加遮罩
if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
[self.bgIV addMaskWithType:MaskTypeCornerBottom cornerRadius:22.0];
[self.audioIV addMaskWithType:MaskTypeAllCorner cornerRadius:15.5];
}
[self.bgIV setCornerRadiusRect:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadius:22.0];
} else {
[self.audioIV cornerRadius:15.5];
self.bgIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .3, .5);
self.audioIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .3, .5);
}
}
return self;
}
#pragma mark - lazy
- (UIImageView *)bgIV {
if (!_bgIV) {
_bgIV = [UIImageView new];
_bgIV.contentMode = UIViewContentModeScaleAspectFill;
}
return _bgIV;
}
- (UIImageView *)audioIV {
if (!_audioIV) {
_audioIV = [UIImageView new];
}
return _audioIV;
}
- (UILabel *)audioNameLab {
if (!_audioNameLab) {
_audioNameLab = [UILabel labWithFont:BoldFont(16.0)];
_audioNameLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, ColorFromHex(0xE8E9E9), DSWhite);
}
return _audioNameLab;
}
- (UILabel *)audioDescLab {
if (!_audioDescLab) {
_audioDescLab = [UILabel labWithFont:SysFont(14.0)];
_audioDescLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
_audioDescLab.numberOfLines = 0;
}
return _audioDescLab;
}
- (UIView *)cornerView {
if (!_cornerView) {
_cornerView = [UIView new];
_cornerView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[_cornerView cornerRadius:24.0];
}
return _cornerView;
}
@end