CNLiveCMineInteHeaderSignView.m
12.2 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
//
// CNLiveCMineInteHeaderSignView.m
// CNLiveCMineModule
//
// Created by open on 2021/12/28.
//
#import "CNLiveCMineInteHeaderSignView.h"
@interface CNLiveCMineInteHeaderSignView()
@property (nonatomic, strong) CNLiveCMineInteScoreModel * scoreModel; //签到数据
@property (nonatomic, strong) CNLiveCMineInteTaskListModel * taskModel;//任务列表及积分数据
@property (nonatomic, strong) CNLiveCMineInteListModel * announModel; //公告数据
@property (nonatomic, strong) CNLiveCMineInteListModel * activModel; //活动数据
@property (nonatomic, strong) UIView * topView;
@property (nonatomic, strong) CAShapeLayer *topMaskLayer;
@property (nonatomic, strong) CAGradientLayer *topGradientLayer;
@property (nonatomic, strong) UILabel * nameLabel;//
@property (nonatomic, strong) UIView * bottemView;
@property (nonatomic, strong) QMUIMarqueeLabel * annouLabel;//公告label
@property (nonatomic, strong) UIImageView * iconView;
@property (nonatomic, strong) UIImageView * moreView;
@property (nonatomic, strong) UIButton * clearButton;
@property (nonatomic, strong) UILabel * titleLabel;
@property (nonatomic, strong) NSMutableArray * coinsViews;
@property (nonatomic, strong) NSMutableArray * numberViews;
@end
@implementation CNLiveCMineInteHeaderSignView
- (instancetype)init
{
self = [super init];
if (self) {
self.coinsViews = [[NSMutableArray alloc] init];
self.numberViews = [[NSMutableArray alloc] init];
[self addSubview:self.bottemView];
[self addSubview:self.topView];
[self addSubview:self.titleLabel];
[self.topView addSubview:self.nameLabel];
[self.bottemView addSubview:self.annouLabel];
[self.bottemView addSubview:self.iconView];
[self.bottemView addSubview:self.moreView];
[self.bottemView addSubview:self.clearButton];
[self setupWithCoinsVeiw];
}
return self;
}
-(void)setupWithCoinsVeiw
{
UIView * coinsView = [[UIView alloc] initWithFrame:CGRectMake(5, 40, SCREEN_WIDTH - 30, 90)];
coinsView.backgroundColor = [UIColor clearColor];
[self.topView addSubview:coinsView];
CGFloat item_w = (SCREEN_WIDTH - 60)/7;
CGFloat item_h = 60.0f;//item_w * 1.33;
for (int i = 0; i < 7; i++) {
UIView * temp_v = [[UIView alloc] initWithFrame:CGRectMake(i * (item_w + 5), 0, item_w, 90)];
temp_v.backgroundColor = [UIColor clearColor];
[coinsView addSubview:temp_v];
UIImageView * coinsV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, item_w, item_h)];
coinsV.image = [UIImage imageWithColor:[UIColor colorWithWhite:0 alpha:0.3]];
coinsV.layer.masksToBounds = YES;
coinsV.layer.cornerRadius = 5;
[temp_v addSubview:coinsV];
[self.coinsViews addObject:coinsV];
UIImageView * coins = [[UIImageView alloc] initWithFrame:CGRectMake((item_w - 30)/2, 5, 30, 30)];
coins.image = [CNLiveCMineService imageWithMineName:@"c_mine_content_gold_coins"];
coins.backgroundColor = [UIColor clearColor];
[coinsV addSubview:coins];
UILabel * numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 35, item_w, 20)];
numberLabel.backgroundColor = [UIColor clearColor];
numberLabel.textColor = [UIColor whiteColor];
numberLabel.textAlignment = NSTextAlignmentCenter;
numberLabel.font = [UIFont systemFontOfSize:10];
numberLabel.text = [NSString stringWithFormat:@"+%d",(i + 1) * 1000];
[coinsV addSubview:numberLabel];
[self.numberViews addObject:numberLabel];
UILabel * dayLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, item_h + 5, item_w, 20)];
dayLabel.backgroundColor = [UIColor clearColor];
dayLabel.textColor = [UIColor whiteColor];
dayLabel.textAlignment = NSTextAlignmentCenter;
dayLabel.font = [UIFont systemFontOfSize:14];
dayLabel.text = [NSString stringWithFormat:@"%d天",i+1];
[temp_v addSubview:dayLabel];
}
}
-(void)layoutSubviews
{
[super layoutSubviews];
__weak typeof(self) weakSelf = self;
[self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.mas_equalTo(weakSelf);
make.bottom.mas_equalTo(weakSelf).offset(-40);
}];
[self.bottemView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(weakSelf.topView.mas_bottom).offset(-20);
make.left.right.mas_equalTo(weakSelf);
make.bottom.mas_equalTo(weakSelf);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(weakSelf.bottemView.mas_bottom).offset(10);
make.left.mas_equalTo(weakSelf.mas_left);
}];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.mas_equalTo(weakSelf).offset(15);
}];
[self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(weakSelf.bottemView).offset(5);
make.left.mas_equalTo(weakSelf.bottemView.mas_left).offset(10);
make.height.mas_equalTo(30);
make.width.mas_equalTo(40);
}];
[self.moreView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(weakSelf.iconView);
make.right.mas_equalTo(weakSelf.bottemView.mas_right).offset(-20);
make.size.mas_equalTo(20);
}];
[self.annouLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(weakSelf.iconView);
make.left.mas_equalTo(weakSelf.iconView.mas_right).offset(10);
make.right.mas_equalTo(weakSelf.moreView.mas_left).offset(-10);
}];
[self.clearButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(weakSelf.bottemView);
}];
self.topMaskLayer.frame = self.topView.bounds;
self.topGradientLayer.frame = self.topView.frame;
}
/// 数据进行赋值
/// @param scoreModel 签到数据
/// @param taskModel 任务数据
/// @param announModel 公告数据
-(void)setupWithScoreModel:(CNLiveCMineInteScoreModel *)scoreModel
taskModel:(CNLiveCMineInteTaskListModel *)taskModel
announModel:(CNLiveCMineInteListModel *)announModel
activModel:(CNLiveCMineInteListModel *)activModel
{
_scoreModel = scoreModel;
_taskModel = taskModel;
_announModel = announModel;
_activModel = activModel;
NSArray * array = [scoreModel.scores.firstObject componentsSeparatedByString:@","];
if (array.count == 0) array = @[@"1000",@"2000",@"3000",@"4000",@"5000",@"6000",@"7000"];
NSInteger index = [array indexOfObject:scoreModel.score];
if (scoreModel) {
for (int i = 0; i < self.numberViews.count; i++) {
UILabel * numberLabel = self.numberViews[i];
UIImageView * coinsV = self.coinsViews[i];
numberLabel.text = [NSString stringWithFormat:@"+%@",array.count >= self.numberViews.count ? array[i] : @""];
numberLabel.textColor = index >= i ? [UIColor blackColor] : [UIColor whiteColor];
coinsV.image = index >= i ? [CNLiveCMineService imageWithMineName:@"c_mine_content_gold_select"] : [UIImage imageWithColor:[UIColor colorWithWhite:0 alpha:0.3]];
}
self.nameLabel.text = [NSString stringWithFormat:@"已连续签到 %ld天",index + 1];
}else{
self.nameLabel.text = @"已连续签到 0天";
}
self.titleLabel.hidden = activModel == nil;
self.bottemView.hidden = announModel.list.count == 0;
self.iconView.hidden = announModel.list.count == 0;
self.moreView.hidden = announModel.list.count == 0;
self.annouLabel.hidden = announModel.list.count == 0;
if (announModel.list.count > 0) {
NSMutableArray * listArray = announModel.list.mutableCopy;
NSMutableString * tempString_roof = [[NSMutableString alloc] init];
NSMutableString * tempString_none = [[NSMutableString alloc] init];
for (CNLiveCMineInteListSubModel * subModel in listArray) {
if ([subModel.model cn_containsString:@"roof"]) {
[tempString_roof appendFormat:@"%@ ",subModel.title];
}
[tempString_none appendFormat:@"%@ ",subModel.title];
}
self.annouLabel.text = !CNLiveStringIsEmpty(tempString_roof) ? tempString_roof : tempString_none;
}
if (announModel == nil) self.titleLabel.top = CGRectGetMaxY(self.topView.frame) + 10;
}
-(void)pushAnnouMedthod:(UIButton *)button
{
if (self.clickActionBlock) self.clickActionBlock(self.scoreModel, self.taskModel, self.announModel,CNLiveCMineInteHeaderClickAnnotation);
}
#pragma mark =
-(UILabel *)titleLabel
{
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.textColor = [UIColor blackColor];
_titleLabel.font = UIFontCNMake(15);
_titleLabel.font = UIFontBoldCNMake(15);
_titleLabel.text = @"积分乐园";
_titleLabel.hidden = YES;
}
return _titleLabel;
}
-(UILabel *)nameLabel
{
if (!_nameLabel) {
_nameLabel = [[UILabel alloc] init];
_nameLabel.textColor = [UIColor whiteColor];
_nameLabel.font = UIFontCNMake(15);
_nameLabel.font = UIFontBoldCNMake(15);
}
return _nameLabel;
}
-(UIButton *)clearButton
{
if (!_clearButton) {
_clearButton = [UIButton buttonWithType:UIButtonTypeCustom];
_clearButton.backgroundColor = [UIColor clearColor];
[_clearButton addTarget:self action:@selector(pushAnnouMedthod:) forControlEvents:UIControlEventTouchUpInside];
}
return _clearButton;
}
-(QMUIMarqueeLabel *)annouLabel
{
if (!_annouLabel) {
_annouLabel = [[QMUIMarqueeLabel alloc] qmui_initWithFont:[UIFont fontWithName:@"PingFangSC-Medium" size:13] textColor:UIColorHex(666666)];
_annouLabel.textAlignment = NSTextAlignmentCenter;
_annouLabel.automaticallyValidateVisibleFrame = NO;
[_annouLabel qmui_calculateHeightAfterSetAppearance];
_annouLabel.shouldFadeAtEdge = YES;
_annouLabel.backgroundColor = kWhiteColor;
_annouLabel.fadeWidthPercent = 0.1;
_annouLabel.pauseDurationWhenMoveToEdge = 0;
_annouLabel.speed = 1;// 调节滚动速度
}
return _annouLabel;
}
-(UIImageView *)iconView
{
if (!_iconView) {
_iconView = [[UIImageView alloc] initWithFrame:CGRectZero];
_iconView.contentMode = UIViewContentModeScaleAspectFit;
_iconView.backgroundColor = [UIColor whiteColor];
_iconView.image = [CNLiveCMineService imageWithMineName:@"c_mine_content_announ"];
}
return _iconView;
}
-(UIImageView *)moreView
{
if (!_moreView) {
_moreView = [[UIImageView alloc] initWithFrame:CGRectZero];
_moreView.contentMode = UIViewContentModeScaleAspectFit;
_moreView.backgroundColor = [UIColor whiteColor];
_moreView.image = [CNLiveCMineService imageWithMineName:@"c_mine_skip_more"];
}
return _moreView;
}
- (UIView *)topView
{
if (!_topView) {
_topView = [[UIView alloc] init];
_topView.backgroundColor = [UIColor whiteColor];
CAGradientLayer *topGradientLayer = [CAGradientLayer layer];
topGradientLayer.colors = @[(__bridge id)UIColorHex(0xfe7b72).CGColor, (__bridge id)UIColorHex(0xf85948).CGColor];
topGradientLayer.locations = @[@0.5, @1.0];
topGradientLayer.startPoint = CGPointMake(0, 0);
topGradientLayer.endPoint = CGPointMake(1.0, 0);
[_topView.layer addSublayer:topGradientLayer];
_topGradientLayer = topGradientLayer;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_WIDTH - 20, 130) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12, 12)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.path = maskPath.CGPath;
_topView.layer.mask = maskLayer;
_topMaskLayer = maskLayer;
}
return _topView;
}
-(UIView *)bottemView
{
if (!_bottemView) {
_bottemView = [[UIView alloc] init];
_bottemView.backgroundColor = [UIColor whiteColor];
_bottemView.layer.cornerRadius = 12;
_bottemView.layer.masksToBounds = YES;//超出父视图部分不显示。
_bottemView.layer.borderColor = UIColorMakeWithRGBA(234, 7, 15, 0.3).CGColor;
_bottemView.layer.borderWidth = 0.5;
}
return _bottemView;
}
@end