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
//
// ICRAnnocementContentView.m
// XFFruit
//
// Created by Lili Wang on 15/4/14.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#define PRIORITY_LABEL_HEIGHT 30
#define PRIORITY_LABEL_LEFT_PANDING 15
#define PRIORITY_IMAGE_TOP_PANDING 20
#define TITLE_LABEL_TOP_PANDING 15
#define TITLE_LABEL_HEIGHT 15
#define CREAT_BY_LABEL_HEIGHT 14
#define CREAT_BY_LABEL_TOP_PANDING 6
#define CREAT_BY_TEXT_COLOR [UIColor colorWithRed:0.749f green:0.749f blue:0.749f alpha:1.00f]
#import "ICRAnnocementContentView.h"
#import "ICRAnnouncement.h"
@interface ICRAnnocementContentView ()
@property (strong, nonatomic) UILabel *m_priorityLabel;
@property (strong, nonatomic) UILabel *m_titleLabel;
@property (strong, nonatomic) UILabel *m_creatByLabel;
@property (strong, nonatomic) UILabel *m_creatTimeLabel;
@property (strong, nonatomic) UILabel *m_creatByValueLabel;
@property (strong, nonatomic) UILabel *m_creatTimeValueLabel;
@end
@implementation ICRAnnocementContentView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// code
[self _init];
}
return self;
}
- (void)layoutSubviews {
_m_priorityLabel.frame = (CGRect){
.origin.x = PRIORITY_LABEL_LEFT_PANDING,
.origin.y = (self.height - PRIORITY_LABEL_HEIGHT)/2,
.size.width = PRIORITY_LABEL_HEIGHT,
.size.height = PRIORITY_LABEL_HEIGHT
};
CGFloat fMaxW = self.width - PRIORITY_LABEL_LEFT_PANDING;
CGSize size = CGSizeMake( fMaxW - _m_priorityLabel.right , TITLE_LABEL_HEIGHT);
size = [_m_titleLabel widthLimitedSizeThatFits:size];
_m_titleLabel.frame = (CGRect){
.origin.x = _m_priorityLabel.right + CREAT_BY_LABEL_TOP_PANDING,
.origin.y = _m_priorityLabel.top,
.size = size
};
size = CGSizeMake( fMaxW - _m_priorityLabel.right , TITLE_LABEL_HEIGHT);
size = [_m_creatByLabel widthLimitedSizeThatFits:size];
_m_creatByLabel.frame = (CGRect){
.origin.x = _m_priorityLabel.right + CREAT_BY_LABEL_TOP_PANDING,
.origin.y = CREAT_BY_LABEL_TOP_PANDING + _m_titleLabel.bottom,
.size = size
};
size = CGSizeMake( fMaxW - _m_creatByLabel.right,CREAT_BY_LABEL_HEIGHT );
size = [_m_creatByValueLabel widthLimitedSizeThatFits:size];
_m_creatByValueLabel.frame = (CGRect){
.origin.x = _m_creatByLabel.right,
.origin.y = _m_creatByLabel.top,
.size.width = size.width,
.size.height = _m_creatByLabel.height
};
size = CGSizeMake( fMaxW - _m_creatByValueLabel.right , _m_creatByLabel.height );
size = [_m_creatTimeLabel widthLimitedSizeThatFits:size];
_m_creatTimeLabel.frame = (CGRect){
.origin.x = _m_creatByValueLabel.right + CREAT_BY_LABEL_TOP_PANDING,
.origin.y = _m_creatByValueLabel.top,
.size.width = size.width,
.size.height = _m_creatByValueLabel.height
};
size = CGSizeMake( fMaxW - _m_creatTimeLabel.right, _m_creatTimeLabel.height);
size = [_m_creatTimeValueLabel widthLimitedSizeThatFits:size];
_m_creatTimeValueLabel.frame = (CGRect){
.origin.x = _m_creatTimeLabel.right,
.origin.y = _m_creatTimeLabel.top,
.size.width = size.width,
.size.height = _m_creatTimeLabel.height
};
}
#pragma mark - Private Method
- (void)_init {
self.m_priorityLabel = [[self class ]creatLabelWithTextColor:[UIColor whiteColor]
textFont:[UIFont systemFontOfSize:14]
textAlignment:NSTextAlignmentCenter];
_m_priorityLabel.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:@"PriorityTagGrey"]];
_m_priorityLabel.layer.masksToBounds = YES;
_m_priorityLabel.layer.cornerRadius = PRIORITY_LABEL_HEIGHT * 0.5;
[self addSubview:_m_priorityLabel];
self.m_titleLabel = [[self class ] creatLabelWithTextColor:[UIColor colorWithRed:0.165f green:0.165f blue:0.165f alpha:1.00f]
textFont:[UIFont systemFontOfSize:15]
textAlignment:NSTextAlignmentLeft];
[self addSubview:_m_titleLabel];
self.m_creatByLabel = [[self class ] creatLabelWithTextColor:CREAT_BY_TEXT_COLOR
textFont:[UIFont systemFontOfSize:13]
textAlignment:NSTextAlignmentLeft];
_m_creatByLabel.text = [IBTCommon localizableString:@"Publisher:"];
[self addSubview:_m_creatByLabel];
self.m_creatTimeLabel = [[self class ] creatLabelWithTextColor:CREAT_BY_TEXT_COLOR
textFont:[UIFont systemFontOfSize:13]
textAlignment:NSTextAlignmentLeft];
_m_creatTimeLabel.text = [IBTCommon localizableString:@"Publish Time:"];
[self addSubview:_m_creatTimeLabel];
self.m_creatByValueLabel = [[self class ] creatLabelWithTextColor:CREAT_BY_TEXT_COLOR
textFont:[UIFont systemFontOfSize:13]
textAlignment:NSTextAlignmentLeft];;
[self addSubview:_m_creatByValueLabel];
self.m_creatTimeValueLabel = [[self class ] creatLabelWithTextColor:CREAT_BY_TEXT_COLOR
textFont:[UIFont systemFontOfSize:13]
textAlignment:NSTextAlignmentLeft];;
[self addSubview:_m_creatTimeValueLabel];
}
#pragma mark - Private Method
+ (UILabel *)creatLabelWithTextColor:(UIColor *)textColor
textFont:(UIFont *)textFont
textAlignment:(NSTextAlignment)textAlignment {
UILabel *label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.textColor = textColor;
label.font = textFont;
label.textAlignment = textAlignment;
return label;
}
#pragma mark - Public Method
- (void)updateContentWithData:(id)aAnnouncement {
/*
kICRAnnouncementStatusHigh = 0,
kICRAnnouncementStatusLow,
kICRAnnouncementStatusNormal
*/
/*
kICRAnnouncementTypeReaded = 0,
kICRAnnouncementTypeUnread
*/
/*
"Low" = "低";
"Normal" = "中";
"High" = "高";
*/
if ([aAnnouncement isKindOfClass:[ICRAnnouncement class]]) {
ICRAnnouncement *announcement = aAnnouncement;
switch (announcement.state) {
case kICRAnnouncementTypeUnread:
{
switch (announcement.priority) {
case kICRAnnouncementStatusLow:
{
self.m_priorityLabel.text = [IBTCommon localizableString:@"Low"];
self.m_priorityLabel.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:@"PriorityTagGreen"]];
}
break;
case kICRAnnouncementStatusNormal:
{
self.m_priorityLabel.text = [IBTCommon localizableString:@"Normal"];
self.m_priorityLabel.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:@"PriorityTagOrange"]];
}
break;
case kICRAnnouncementStatusHigh:
{
self.m_priorityLabel.text = [IBTCommon localizableString:@"High"];
self.m_priorityLabel.backgroundColor = [UIColor colorWithPatternImage:
[UIImage imageNamed:@"PriorityTagRed"]];
}
break;
default:
break;
}
}
break;
case kICRAnnouncementTypeReaded:
{
switch (announcement.priority) {
case kICRAnnouncementStatusLow:
{
self.m_priorityLabel.text = [IBTCommon localizableString:@"Low"];
}
break;
case kICRAnnouncementStatusNormal:
{
self.m_priorityLabel.text = [IBTCommon localizableString:@"Normal"];
}
break;
case kICRAnnouncementStatusHigh:
{
self.m_priorityLabel.text = [IBTCommon localizableString:@"High"];
}
break;
default:
break;
}
self.m_priorityLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"PriorityTagGrey"]];
}
break;
default:
break;
}
self.m_titleLabel.text = announcement.title ? : @"";
self.m_creatByValueLabel.text = [announcement createInfo ][@"operator"][@"operName"] ? :@"";
self.m_creatTimeValueLabel.text = [announcement createInfo ][@"time"]? : @"";
}
[self setNeedsLayout];
}
@end