-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathLeftImage_LRTextCell.m
executable file
·167 lines (158 loc) · 6.74 KB
/
LeftImage_LRTextCell.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
// LeftImage_LRTextCell.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-19.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "LeftImage_LRTextCell.h"
#import "Task.h"
@interface LeftImage_LRTextCell ()
@property (strong, nonatomic) id aObj;
@property (assign, nonatomic) LeftImage_LRTextCellType type;
@property (strong, nonatomic) UIImageView *iconView;
@property (strong, nonatomic) UILabel *leftLabel, *rightLabel;
@end
@implementation LeftImage_LRTextCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (!_iconView) {
_iconView = [[YLImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, ([LeftImage_LRTextCell cellHeight] - 33) / 2, 33, 33)];
[self.contentView addSubview:_iconView];
}
if (!_leftLabel) {
_leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, ([LeftImage_LRTextCell cellHeight] - 30) / 2, 80, 30)];
_leftLabel.font = [UIFont systemFontOfSize:15];
_leftLabel.textColor = kColorDark3;
_leftLabel.textAlignment = NSTextAlignmentLeft;
[self.contentView addSubview:_leftLabel];
}
if (!_rightLabel) {
_rightLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_leftLabel.frame), ([LeftImage_LRTextCell cellHeight] - 30) / 2, kScreen_Width - CGRectGetMaxX(_leftLabel.frame) - 35, 30)];
_rightLabel.font = [UIFont systemFontOfSize:15];
_rightLabel.textColor = kColorDark7;
_rightLabel.textAlignment = NSTextAlignmentRight;
[self.contentView addSubview:_rightLabel];
}
}
return self;
}
- (void)setObj:(id)aObj type:(LeftImage_LRTextCellType)type{
_aObj = aObj;
_type = type;
}
- (void)layoutSubviews{
[super layoutSubviews];
self.userInteractionEnabled = YES;
if ([_aObj isKindOfClass:[Task class]]) {
Task *task = (Task *)_aObj;
switch (_type) {
case LeftImage_LRTextCellTypeTaskProject:
{
[_iconView doCircleFrame];
[_iconView sd_setImageWithURL:[task.project.icon urlImageWithCodePathResizeToView:_iconView] placeholderImage:[UIImage imageNamed:@"taskProject"]];
_leftLabel.text = @"所属项目";
if (task.project) {
_rightLabel.text = [NSString stringWithFormat:@"%@/%@", task.project.owner_user_name, task.project.name];
}else{
_rightLabel.text = @"未指定";
}
self.userInteractionEnabled = (task.handleType == TaskHandleTypeAddWithoutProject);
}
break;
case LeftImage_LRTextCellTypeTaskOwner:
{
[_iconView doCircleFrame];
[_iconView sd_setImageWithURL:[task.owner.avatar urlImageWithCodePathResizeToView:_iconView] placeholderImage:[UIImage imageNamed:@"taskOwner"]];
_leftLabel.text = @"执行者";
if (task.owner) {
_rightLabel.text = task.owner.name;
}else{
_rightLabel.text = @"未指定";
}
}
break;
case LeftImage_LRTextCellTypeTaskBoardList:
{
[_iconView doNotCircleFrame];
[_iconView setImage:[UIImage imageNamed:@"taskBoardList"]];
_leftLabel.text = @"看板列表";
if (task.task_board_list) {
_rightLabel.text = task.task_board_list.title;
}else{
_rightLabel.text = @"未指定";
}
}
break;
case LeftImage_LRTextCellTypeTaskPriority:
{
[_iconView doNotCircleFrame];
[_iconView setImage:[UIImage imageNamed:@"taskPriority"]];
_leftLabel.text = @"优先级";
if (task.priority && task.priority.intValue < kTaskPrioritiesDisplay.count) {
_rightLabel.text = kTaskPrioritiesDisplay[task.priority.intValue];
}else{
_rightLabel.text = @"未指定";
}
}
break;
case LeftImage_LRTextCellTypeTaskDeadline:
{
[_iconView doNotCircleFrame];
[_iconView setImage:[UIImage imageNamed:@"taskDeadline"]];
_leftLabel.text = @"截止日期";
if (task.deadline_date) {
_rightLabel.text = [NSDate stringFromDate:task.deadline_date withFormat:@"MM月dd日"];
}else{
_rightLabel.text = @"未指定";
}
}
break;
case LeftImage_LRTextCellTypeTaskWatchers:
{
[_iconView doNotCircleFrame];
[_iconView setImage:[UIImage imageNamed:@"taskWatchers"]];
_leftLabel.text = @"关注者";
_rightLabel.text = task.watchers.count > 0? [NSString stringWithFormat:@"%lu 人关注", (unsigned long)task.watchers.count]: @"未添加";
}
break;
case LeftImage_LRTextCellTypeTaskStatus:
{
[_iconView doNotCircleFrame];
[_iconView setImage:[UIImage imageNamed:@"taskProgress"]];
_leftLabel.text = @"阶段";
if (task.status) {
_rightLabel.text = task.status.intValue == 1? @"未完成":@"已完成";
}else{
_rightLabel.text = @"未指定";
}
self.userInteractionEnabled = (task.handleType == TaskHandleTypeEdit);
}
break;
case LeftImage_LRTextCellTypeTaskResourceReference:
{
[_iconView doNotCircleFrame];
[_iconView setImage:[UIImage imageNamed:@"taskResourceReference"]];
_leftLabel.text = @"关联资源";
_rightLabel.text = [NSString stringWithFormat:@"%lu 个资源", (unsigned long)task.resourceReference.itemList.count];
}
break;
default:
break;
}
if ((_type == LeftImage_LRTextCellTypeTaskProject && task.project.icon.length > 0) ||
(_type == LeftImage_LRTextCellTypeTaskOwner && task.owner.avatar.length > 0)) {
_iconView.contentMode = UIViewContentModeScaleAspectFill;
}else{
_iconView.contentMode = UIViewContentModeCenter;
}
}
}
+ (CGFloat)cellHeight{
return 50;
}
@end