FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Coding-iOS/Coding_iOS/Views/EaseUserHeaderView.m at master · feihuohua/Coding-iOS · GitHub
feihuohua
/
Coding-iOS
Public
forked from
coding/Coding-iOS
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Views
/
EaseUserHeaderView.m
Copy path
More file actions
More file actions
Latest commit
History
History
History
271 lines (232 loc) · 10.1 KB
Breadcrumbs
Coding-iOS
/
Coding_iOS
/
Views
/
EaseUserHeaderView.m
Copy path
File metadata and controls
271 lines (232 loc) · 10.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
//
EaseUserHeaderView.m
//
Coding_iOS
//
//
Created by Ease on 15/3/17.
//
Copyright (c) 2015年 Coding. All rights reserved.
//
#
define
EaseUserHeaderView_Height_Me
kScaleFrom_iPhone5_Desgin
(
190
)
#
define
EaseUserHeaderView_Height_Other
kScaleFrom_iPhone5_Desgin
(
250
)
#
import
"
EaseUserHeaderView.h
"
#
import
<
UIImage+BlurredFrame/UIImage+BlurredFrame.h
>
@interface
EaseUserHeaderView
()
@property
(
strong
,
nonatomic
) UITapImageView *userIconView, *userSexIconView;
@property
(
strong
,
nonatomic
) UILabel *userLabel;
@property
(
strong
,
nonatomic
) UIButton *fansCountBtn, *followsCountBtn, *followBtn;
@property
(
strong
,
nonatomic
) UIView *splitLine, *coverView;
@property
(
assign
,
nonatomic
) CGFloat userIconViewWith;
@end
@implementation
EaseUserHeaderView
+ (
id
)
userHeaderViewWithUser
:
(User *)
user
image
:
(UIImage *)
image
{
if
(!user || !image) {
return
nil
;
}
EaseUserHeaderView *headerView = [[EaseUserHeaderView
alloc
]
init
];
headerView.
userInteractionEnabled
=
YES
;
headerView.
contentMode
= UIViewContentModeScaleAspectFill;
headerView.
curUser
= user;
headerView.
bgImage
= image;
[headerView
configUI
];
return
headerView;
}
- (
void
)
setCurUser
:
(User *)
curUser
{
_curUser = curUser;
[
self
updateData
];
}
- (
void
)
setBgImage
:
(UIImage *)
bgImage
{
_bgImage = bgImage;
[
self
updateData
];
}
- (
void
)
setNameBtnClicked
:
(
void
(^)())
nameBtnClicked
{
_nameBtnClicked = nameBtnClicked;
if
(_nameBtnClicked) {
[_userSexIconView
setImage:
[UIImage
imageNamed:
@"
user_info_edit
"
]];
_userSexIconView.
userInteractionEnabled
= _userLabel.
userInteractionEnabled
=
YES
;
[_userSexIconView
bk_whenTapped:
_nameBtnClicked];
[_userLabel
bk_whenTapped:
_nameBtnClicked];
}
else
{
[_userLabel
bk_whenTapped:
nil
];
[_userSexIconView
bk_whenTapped:
nil
];
}
}
- (
void
)
configUI
{
if
(!_curUser) {
return
;
}
if
(!_coverView) {
//
遮罩
_coverView = [[UIView
alloc
]
init
];
_coverView.
backgroundColor
= [[UIColor
blackColor
]
colorWithAlphaComponent:
0.4
];
[
self
addSubview:
_coverView];
[_coverView
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
edges
.
equalTo
(self);
}];
}
BOOL
isMe = [_curUser.global_key
isEqualToString:
[Login
curLoginUser
].global_key];
CGFloat viewHeight = isMe? EaseUserHeaderView_Height_Me: EaseUserHeaderView_Height_Other;
[
self
setFrame:
CGRectMake
(
0
,
0
,
kScreen_Width
, viewHeight)];
__weak
typeof
(self) weakSelf = self;
if
(!_fansCountBtn) {
_fansCountBtn = [UIButton
buttonWithType:
UIButtonTypeCustom];
_fansCountBtn.
contentHorizontalAlignment
= UIControlContentHorizontalAlignmentRight;
[_fansCountBtn
bk_addEventHandler:
^(
id
sender) {
if
(weakSelf.
fansCountBtnClicked
) {
weakSelf.
fansCountBtnClicked
();
}
}
forControlEvents:
UIControlEventTouchUpInside];
[
self
addSubview:
_fansCountBtn];
}
if
(!_followsCountBtn) {
_followsCountBtn = [UIButton
buttonWithType:
UIButtonTypeCustom];
_followsCountBtn.
contentHorizontalAlignment
= UIControlContentHorizontalAlignmentLeft;
[_followsCountBtn
bk_addEventHandler:
^(
id
sender) {
if
(weakSelf.
followsCountBtnClicked
) {
weakSelf.
followsCountBtnClicked
();
}
}
forControlEvents:
UIControlEventTouchUpInside];
[
self
addSubview:
_followsCountBtn];
}
if
(!_splitLine) {
_splitLine = [[UIView
alloc
]
init
];
_splitLine.
backgroundColor
= [UIColor
colorWithHexString:
@"
0xcacaca
"
];
[
self
addSubview:
_splitLine];
}
if
(!isMe && !_followBtn) {
_followBtn = [UIButton
buttonWithType:
UIButtonTypeCustom];
[_followBtn
bk_addEventHandler:
^(
id
sender) {
if
(weakSelf.
followBtnClicked
) {
weakSelf.
followBtnClicked
();
}
}
forControlEvents:
UIControlEventTouchUpInside];
[
self
addSubview:
_followBtn];
}
else
{
_followBtn.
hidden
=
YES
;
}
if
(!_userLabel) {
_userLabel = [[UILabel
alloc
]
init
];
_userLabel.
font
= [UIFont
boldSystemFontOfSize:
18
];
_userLabel.
textColor
= [UIColor
whiteColor
];
_userLabel.
textAlignment
= NSTextAlignmentCenter;
[
self
addSubview:
_userLabel];
}
if
(!_userIconView) {
_userIconView = [[UITapImageView
alloc
]
init
];
_userIconView.
backgroundColor
=
kColorTableBG
;
[_userIconView
addTapBlock:
^(
id
obj) {
if
(weakSelf.
userIconClicked
) {
weakSelf.
userIconClicked
();
}
}];
[
self
addSubview:
_userIconView];
}
if
(
kDevice_Is_iPhone6Plus
) {
_userIconViewWith =
100
;
}
else
if
(
kDevice_Is_iPhone6
){
_userIconViewWith =
90
;
}
else
{
_userIconViewWith =
75
;
}
if
(!_userSexIconView) {
_userSexIconView = [[UITapImageView
alloc
]
init
];
[_userIconView
doBorderWidth:
1.0
color:
nil
cornerRadius:
_userIconViewWith/
2
];
[
self
addSubview:
_userSexIconView];
}
[_fansCountBtn
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
left
.
equalTo
(self.
mas_left
);
make.
right
.
equalTo
(_splitLine.
mas_left
).
offset
(
kScaleFrom_iPhone5_Desgin
(-
15
));
make.
bottom
.
equalTo
(self.
mas_bottom
).
offset
(
kScaleFrom_iPhone5_Desgin
(-
15
));
}];
[_followsCountBtn
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
right
.
equalTo
(self.
mas_right
);
make.
left
.
equalTo
(_splitLine.
mas_right
).
offset
(
kScaleFrom_iPhone5_Desgin
(
15
));
make.
height
.
equalTo
(@[_fansCountBtn.mas_height, @
kScaleFrom_iPhone5_Desgin
(
20
)]);
}];
[_splitLine
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
centerX
.
equalTo
(self.
mas_centerX
);
make.
centerY
.
equalTo
(@[_fansCountBtn, _followsCountBtn]);
make.
size
.
mas_equalTo
(
CGSizeMake
(
0.5
,
15
));
}];
if
(!isMe) {
[_followBtn
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
bottom
.
equalTo
(_fansCountBtn.
mas_top
).
offset
(-
20
);
make.
size
.
mas_equalTo
(
CGSizeMake
(
128
,
39
));
make.
centerX
.
equalTo
(self);
}];
[_userLabel
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
bottom
.
equalTo
(_followBtn.
mas_top
).
offset
(
kScaleFrom_iPhone5_Desgin
(-
25
));
make.
height
.
mas_equalTo
(
kScaleFrom_iPhone5_Desgin
(
20
));
}];
}
else
{
[_userLabel
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
bottom
.
equalTo
(_fansCountBtn.
mas_top
).
offset
(
kScaleFrom_iPhone5_Desgin
(-
20
));
make.
height
.
mas_equalTo
(
kScaleFrom_iPhone5_Desgin
(
20
));
}];
}
[_userIconView
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
size
.
mas_equalTo
(
CGSizeMake
(_userIconViewWith, _userIconViewWith));
make.
bottom
.
equalTo
(_userLabel.
mas_top
).
offset
(-
15
);
make.
centerX
.
equalTo
(self);
}];
CGFloat userSexIconViewWidth = (
14
);
[_userSexIconView
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
size
.
mas_equalTo
(
CGSizeMake
(userSexIconViewWidth, userSexIconViewWidth));
make.
left
.
equalTo
(_userLabel.
mas_right
).
offset
(
5
);
make.
centerY
.
equalTo
(_userLabel);
}];
//
left, right 只是占位,使名字和性别能居中显示
UIView *left = [[UIView
alloc
]
init
], *right = [[UIView
alloc
]
init
];
[
self
addSubview:
left];
[
self
addSubview:
right];
[left
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
size
.
equalTo
(right);
make.
left
.
equalTo
(self);
make.
right
.
equalTo
(_userLabel.
mas_left
);
}];
[right
mas_makeConstraints:
^(MASConstraintMaker *make) {
make.
right
.
equalTo
(self);
make.
left
.
equalTo
(_userSexIconView.
mas_right
);
make.
centerY
.
equalTo
(@[_userLabel, left]);
}];
[
self
updateData
];
}
- (
NSMutableAttributedString
*)
getStringWithTitle
:
(
NSString
*)
title
andValue
:
(
NSString
*)
value
{
NSMutableAttributedString
*attrString = [[
NSMutableAttributedString
alloc
]
initWithString:
[
NSString
stringWithFormat:
@"
%@
%@
"
, value, title]];
[attrString
addAttributes:
@{
NSFontAttributeName
: [UIFont
boldSystemFontOfSize:
17
],
NSForegroundColorAttributeName
: [UIColor
whiteColor
]}
range:
NSMakeRange
(
0
, value.length)];
[attrString
addAttributes:
@{
NSFontAttributeName
: [UIFont
systemFontOfSize:
14
],
NSForegroundColorAttributeName
: [UIColor
whiteColor
]}
range:
NSMakeRange
(value.length+
1
, title.length)];
return
attrString;
}
- (
void
)
updateData
{
if
(!_userIconView) {
return
;
}
self.
image
= _bgImage;
[_userIconView
sd_setImageWithURL:
[_curUser.avatar
urlImageWithCodePathResize:
2
* _userIconViewWith]
placeholderImage:
kPlaceholderMonkeyRoundWidth
(
54.0
)];
[_userSexIconView
setImage:
[UIImage
imageNamed:
(_nameBtnClicked !=
nil
?
@"
user_info_edit
"
:
//
编辑
_curUser.sex.intValue ==
0
?
@"
n_sex_man_icon
"
:
//
男
_curUser.sex.intValue ==
1
?
@"
n_sex_woman_icon
"
:
//
女
@"
"
)]];
//
未知
_userLabel.
text
= _curUser.
name
;
[_userLabel
sizeToFit
];
[_fansCountBtn
setAttributedTitle:
[
self
getStringWithTitle:
@"
粉丝
"
andValue:
_curUser.fans_count.stringValue]
forState:
UIControlStateNormal];
[_followsCountBtn
setAttributedTitle:
[
self
getStringWithTitle:
@"
关注
"
andValue:
_curUser.follows_count.stringValue]
forState:
UIControlStateNormal];
NSString
*imageName;
if
(_curUser.
followed
.
boolValue
) {
if
(_curUser.
follow
.
boolValue
) {
imageName =
@"
n_btn_followed_both
"
;
}
else
{
imageName =
@"
n_btn_followed_yes
"
;
}
}
else
{
imageName =
@"
n_btn_followed_not
"
;
}
[_followBtn
setImage:
[UIImage
imageNamed:
imageName]
forState:
UIControlStateNormal];
}
- (CGFloat)
originalHeight
{
BOOL
isMe = [_curUser.global_key
isEqualToString:
[Login
curLoginUser
].global_key];
CGFloat viewHeight = isMe? EaseUserHeaderView_Height_Me: EaseUserHeaderView_Height_Other;
return
viewHeight;
}
@end
Back
|
FazBrowse Home
|
New Git URL