-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathMemberCell.m
executable file
·150 lines (138 loc) · 5.46 KB
/
MemberCell.m
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
//
// MemberCell.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-20.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "MemberCell.h"
#import "Login.h"
@interface MemberCell ()
@property (strong, nonatomic) UIImageView *memberIconView, *typeIconView;
@property (strong, nonatomic) UILabel *memberNameLabel, *memberAliasLabel;
@end
@implementation MemberCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
if (!_memberIconView) {
_memberIconView = [[YLImageView alloc] initWithFrame:CGRectMake(10, ([MemberCell cellHeight]-40)/2, 40, 40)];
[_memberIconView doCircleFrame];
[self.contentView addSubview:_memberIconView];
}
if (!_memberNameLabel) {
_memberNameLabel = [UILabel new];
_memberNameLabel.font = [UIFont systemFontOfSize:17];
_memberNameLabel.textColor = kColor222;
[self.contentView addSubview:_memberNameLabel];
}
if (!_typeIconView) {
_typeIconView = [UIImageView new];
[self.contentView addSubview:_typeIconView];
[_typeIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.memberNameLabel.mas_right).offset(10);
make.centerY.equalTo(self.memberNameLabel);
make.size.mas_equalTo(CGSizeMake(16, 16));
}];
}
if (!_memberAliasLabel) {
_memberAliasLabel = [UILabel new];
_memberAliasLabel.font = [UIFont systemFontOfSize:12];
_memberAliasLabel.textColor = kColor666;
[self.contentView addSubview:_memberAliasLabel];
[_memberAliasLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.memberNameLabel);
make.height.mas_equalTo(20);
make.centerY.equalTo(self.contentView).offset(10);
}];
}
if (!_leftBtn) {
_leftBtn = [UIButton new];
[_leftBtn addTarget:self action:@selector(leftBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:_leftBtn];
[_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(80, 32));
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.contentView).offset(-kPaddingLeftWidth);
}];
}
}
return self;
}
- (void)setCurMember:(ProjectMember *)curMember{
_curMember = curMember;
if (!_curMember) {
return;
}
[_memberIconView sd_setImageWithURL:[_curMember.user.avatar urlImageWithCodePathResizeToView:_memberIconView] placeholderImage:kPlaceholderMonkeyRoundView(_memberIconView)];
_memberNameLabel.text = _curMember.user.name;
if (_curMember.alias.length > 0) {
_memberAliasLabel.text = _curMember.alias;
_memberAliasLabel.hidden = NO;
}else{
_memberAliasLabel.hidden = YES;
}
switch (_curMember.type.integerValue) {
case 100://项目所有者
case 90://项目管理员
case 75://受限成员
{
[_typeIconView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"member_type_%ld", (long)_curMember.type.integerValue]]];
_typeIconView.hidden = NO;
}
break;
case 80://普通成员
default:
{
_typeIconView.hidden = YES;
}
break;
}
if (_type == ProMemTypeTaskWatchers || _type == ProMemTypeTopicWatchers) {//「添加、已添加」按钮
_leftBtn.hidden = NO;
}else if (_type == ProMemTypeProject){
if (_curMember.user_id.intValue != [Login curLoginUser].id.integerValue) {//「私信」按钮
// 别人
[_leftBtn configPriMsgBtnWithUser:_curMember.user fromCell:YES];
// _leftBtn.hidden = NO;
_leftBtn.hidden = YES;//说是不要私信按钮了
}else{
// 自己
_leftBtn.hidden = YES;//说是也不要退出按钮了
// if (_curMember.type.intValue == 100) {//项目创建者不能「退出」
// _leftBtn.hidden = YES;
// }else{//「退出」按钮
// [_leftBtn setImage:[UIImage imageNamed:@"btn_project_quit"] forState:UIControlStateNormal];
// [_leftBtn setTitle:@"- 退出项目" forState:UIControlStateNormal];
// _leftBtn.hidden = NO;
// }
}
}else{
_leftBtn.hidden = YES;
}
[_memberNameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.memberIconView.mas_right).offset(10);
make.height.mas_equalTo(20);
make.centerY.equalTo(self.contentView).offset(_curMember.alias.length > 0? -10: 0);
if (_leftBtn.hidden) {
make.right.lessThanOrEqualTo(self.contentView).offset(_typeIconView.hidden? -15: -40);
}else{
make.right.lessThanOrEqualTo(_leftBtn.mas_left).offset(_typeIconView.hidden? -10: -35);
}
}];
}
- (void)leftBtnClicked:(id)sender{
if (self.leftBtnClickedBlock) {
self.leftBtnClickedBlock(sender);
}
}
+ (CGFloat)cellHeight{
return 60;
}
- (void)prepareForReuse{
[super prepareForReuse];
[_leftBtn stopQueryAnimate];
}
@end