SignTaskView.m
4.4 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
//
// SignTaskView.m
// DreamSleep
//
// Created by peter on 2022/6/7.
//
#import "SignTaskView.h"
#import "SignCollectionViewCell.h"
@interface SignTaskView () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UICollectionView *signMainView;
@property (nonatomic, strong) UIButton *signBtn;
/// 签到列表
@property (nonatomic, strong) NSArray *signList;
@property (nonatomic, strong) ScoreTaskRequestModel *requestModel;
@end
@implementation SignTaskView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
[self cornerRadius:24.0];
[self addSubview:self.titleLab];
[self addSubview:self.signMainView];
[self addSubview:self.signBtn];
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.equalTo(self).offset(15);
}];
[self.signMainView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(15);
make.right.equalTo(self).offset(-15);
make.top.equalTo(self.titleLab.mas_bottom).offset(10);
make.bottom.equalTo(self.signBtn.mas_top).offset(-14);
}];
[self.signBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(155, 40));
make.centerX.equalTo(self);
make.bottom.equalTo(self).offset(-15);
}];
}
return self;
}
- (void)signAction {
}
- (void)updateSignView:(ScoreTaskRequestModel *)requestModel {
if (requestModel && requestModel.signList && requestModel.signList.count) {
self.requestModel = requestModel;
self.signList = requestModel.signList;
[self.signMainView reloadData];
}
}
#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.signList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
SignCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SignCollectionViewCell class]) forIndexPath:indexPath];
[cell refreshSignView:self.requestModel indexPath:indexPath];
return cell;
}
#pragma mark - lazy
- (UILabel *)titleLab {
if (!_titleLab) {
_titleLab = [UILabel labWithText:@"签到领积分,连续签到有额外奖励" font:SysFont(12.0) fit:YES];
_titleLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3));
}
return _titleLab;
}
- (UICollectionView *)signMainView {
if (!_signMainView) {
CGFloat space = (kScreenWidth - 60 - 280) / 6.0;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
layout.minimumLineSpacing = 0;
layout.itemSize = CGSizeMake(40 + space, 77);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
_signMainView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_signMainView.backgroundColor = DSClearColor;
_signMainView.scrollEnabled = NO;
[_signMainView registerClass:[SignCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([SignCollectionViewCell class])];
_signMainView.showsHorizontalScrollIndicator = NO;
_signMainView.delegate = self;
_signMainView.dataSource = self;
}
return _signMainView;
}
- (UIButton *)signBtn {
if (!_signBtn) {
_signBtn = [UIButton btnWithTitle:@"签到领积分" font:BoldFont(16)];
[_signBtn dk_setTitleColorPicker:DKColorPickerWithColors(DSWhite, DkTitleColor, DSWhite) forState:UIControlStateNormal];
[_signBtn dk_setBackgroundColorPicker:DKColorPickerWithColors(ColorFromHex(0xFEA961), ColorFromHex(0xB77C4E), DSWhite)];
[_signBtn addTarget:self action:@selector(signAction) forControlEvents:UIControlEventTouchUpInside];
[_signBtn cornerRadius:20];
}
return _signBtn;
}
- (NSArray *)signList {
if (!_signList) {
_signList = [NSArray array];
}
return _signList;
}
@end