RankHeadView.m
9.3 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
//
// RankHeadView.m
// DreamSleep
//
// Created by peter on 2022/7/2.
//
#import "RankHeadView.h"
@interface RankHeadView ()
@property (nonatomic, strong) UIImageView *rankIV;
@property (nonatomic, strong) NSArray *btns;
@property (nonatomic, strong) UIImageView *markerIV;
@property (nonatomic, assign) NSInteger curIndex;
@property (nonatomic, strong) UIView *otherView;
@property (nonatomic, strong) UILabel *myNameLab;
@property (nonatomic, strong) UILabel *myRankLab;
@property (nonatomic, strong) UILabel *myScoreLab;
@end
@implementation RankHeadView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.curIndex = 0;
[self addSubview:self.rankIV];
UIButton *weekBtn = [self buildBtnWithTitle:@"周排行榜" tag:0];
UIButton *totalBtn = [self buildBtnWithTitle:@"月排行榜" tag:1];
self.btns = @[weekBtn, totalBtn];
[self addSubview:self.markerIV];
[self adjustMarkLayout];
[self addSubview:self.otherView];
CGFloat rankIV_H = kScreenWidth * 147 / 375;
[self.rankIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self);
make.height.equalTo(@(rankIV_H));
}];
[weekBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.rankIV.mas_bottom);
make.left.equalTo(self);
make.height.equalTo(@40);
}];
[totalBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(weekBtn);
make.right.equalTo(self);
make.size.equalTo(weekBtn);
make.left.equalTo(weekBtn.mas_right);
}];
[self.otherView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(weekBtn.mas_bottom);
make.left.right.equalTo(self);
make.height.equalTo(@138);
}];
[self layoutIfNeeded];
self.height = CGRectGetMaxY(self.otherView.frame);
}
return self;
}
- (UIButton *)buildBtnWithTitle:(NSString *)title tag:(NSInteger)tag {
WS(weakSelf);
UIButton *btn = [UIButton new];
btn.tag = tag;
[btn addTouchUpInsideHandler:^(NSInteger tag) {
weakSelf.curIndex = tag;
[weakSelf adjustMarkLayout];
if (weakSelf.rankItemBlock) {
weakSelf.rankItemBlock(tag);
}
}];
[btn setTitle:title forState:UIControlStateNormal];
[btn dk_setBackgroundColorPicker:DKColorPickerWithColors(ColorFromHex(0x4670FF), ColorFromHex(0x2341A3), DSWhite)];
[self addSubview:btn];
return btn;
}
- (void)adjustMarkLayout {
[self.btns enumerateObjectsUsingBlock:^(UIButton * obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (self.curIndex == idx) {
[obj setTitleColor:DSWhite forState:UIControlStateNormal];
[obj.titleLabel setFont:BoldFont(16.0)];
} else {
[obj setTitleColor:ColorFromHexA(0xFFFFFF, .8) forState:UIControlStateNormal];
[obj.titleLabel setFont:SysFont(14.0)];
}
}];
UIButton *btn = self.btns[self.curIndex];
[UIView animateWithDuration:.8 animations:^{
[self.markerIV mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(btn);
make.bottom.equalTo(btn);
}];
}];
}
- (void)updateMyRankView:(RankModel *)myRankModel {
self.myNameLab.text = myRankModel.user_name;
self.myRankLab.text = [NSString stringWithFormat:@"第%ld名", myRankModel.rank];
self.myScoreLab.text = [NSString stringWithFormat:@"%ld", myRankModel.points];
}
#pragma mark - lazy
- (UIImageView *)rankIV {
if (!_rankIV) {
_rankIV = [[UIImageView alloc] dk_initWithImagePicker:DKImagePickerWithNames(@"bg_jf_paihangbang", @"dk_bg_jf_paihangbang", @"bg_jf_paihangbang")];
}
return _rankIV;
}
- (UIImageView *)markerIV {
if (!_markerIV) {
_markerIV = [[UIImageView alloc] dk_initWithImagePicker:DKImagePickerWithNames(@"ic_jf_select", @"dk_ic_jf_select", @"ic_jf_select")];
_markerIV.size = CGSizeMake(10, 5);
}
return _markerIV;
}
- (UIView *)otherView {
if (!_otherView) {
_otherView = [UIView new];
UIView *shadowView = [UIView new];
shadowView.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, ColorFromHex(0x1F263F), DSWhite);
[shadowView cornerRadius:12.0];
shadowView.layer.dk_shadowColorPicker = DKColorPickerWithColors(ColorFromRGBA(162.0, 239.0, 254.0, 1.0), ColorFromRGBA(162.0, 239.0, 254.0, .2), DSWhite);
shadowView.layer.shadowOffset = CGSizeMake(0, 1);
shadowView.layer.shadowOpacity = 1;
shadowView.layer.shadowRadius = 4;
[_otherView addSubview:shadowView];
// 我的成绩
UILabel *myScoreTitleLab = [UILabel labWithText:@"我的\n成绩" textColor:BrandColor font:SysFont(14.0)];
myScoreTitleLab.numberOfLines = 0;
[shadowView addSubview:myScoreTitleLab];
// 我的头像
UIImageView *myHeadIV = [UIImageView new];
[myHeadIV cornerRadius:20.0];
myHeadIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1, .5, .5);
[myHeadIV yy_setImageWithURL:[NSURL URLWithString:[LoginUtils getFaceImg]] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
[shadowView addSubview:myHeadIV];
// 我的名称
UILabel *myNameLab = [UILabel labWithFont:SysFont(14.0)];
myNameLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
[shadowView addSubview:myNameLab];
self.myNameLab = myNameLab;
// 我的排名
UILabel *myRankLab = [UILabel labWithTextColor:BrandColor font:SysFont(14.0)];
myRankLab.textAlignment = NSTextAlignmentRight;
[shadowView addSubview:myRankLab];
self.myRankLab = myRankLab;
// 分割线
UIView *lineView = [UIView new];
lineView.backgroundColor = ColorFromHex(0xF5F5F5);
[shadowView addSubview:lineView];
// 我的积分
UILabel *myScoreLab = [UILabel labWithTextColor:BrandColor font:SysFont(14.0)];
myScoreLab.textAlignment = NSTextAlignmentCenter;
[shadowView addSubview:myScoreLab];
self.myScoreLab = myScoreLab;
UILabel *rankLab = [UILabel labWithText:@"排名" font:SysFont(14.0) fit:YES];
rankLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
[_otherView addSubview:rankLab];
UILabel *userLab = [UILabel labWithText:@"用户" font:SysFont(14.0) fit:YES];
userLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
[_otherView addSubview:userLab];
UILabel *scoreLab = [UILabel labWithText:@"积分" font:SysFont(14.0) fit:YES];
scoreLab.textAlignment = NSTextAlignmentCenter;
scoreLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
[_otherView addSubview:scoreLab];
[shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_otherView).offset(24);
make.left.equalTo(_otherView).offset(15);
make.right.equalTo(_otherView).offset(-15);
make.height.equalTo(@64);
}];
[myScoreTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(shadowView).offset(20);
make.centerY.equalTo(shadowView);
}];
[myHeadIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@40);
make.centerY.equalTo(myScoreTitleLab);
make.left.equalTo(myScoreTitleLab.mas_right).offset(20);
}];
[myNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(myHeadIV);
make.left.equalTo(myHeadIV.mas_right).offset(14);
}];
[myRankLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(myHeadIV);
make.left.equalTo(myNameLab.mas_right).offset(20);
make.right.equalTo(lineView.mas_left).offset(-20);
}];
[lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(shadowView);
make.top.equalTo(shadowView).offset(12);
make.right.equalTo(shadowView).offset(-64);
make.width.equalTo(@1);
}];
[myScoreLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(myHeadIV);
make.right.equalTo(shadowView);
make.left.equalTo(lineView.mas_right);
}];
[rankLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_otherView).offset(35);
make.top.equalTo(shadowView.mas_bottom).offset(24);
}];
[userLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(rankLab);
make.left.equalTo(rankLab.mas_right).offset(26);
}];
[scoreLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(rankLab);
make.right.equalTo(_otherView).offset(-15);
make.width.equalTo(@64);
}];
}
return _otherView;
}
@end