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
//
// ICRAnnouncementDetailHeadView.m
// XFFruit
//
// Created by Lili Wang on 15/4/15.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#define LABEL_TEXT_COLOR [UIColor colorWithRed:0.286f green:0.549f blue:0.933f alpha:1.00f]
#define CONTENT_LABEL_TEXT_COLOR [UIColor colorWithRed:0.471f green:0.471f blue:0.478f alpha:1.00f]
#define MYSELF_BACKGROUND_COLOR [UIColor colorWithRed:0.941f green:0.965f blue:0.996f alpha:1.00f]
#define LIMITED_SIZE CGSizeMake( self.width/2 , CREAT_BY_LABEL_HEIGHT )
#define TITLE_IMG_TOP_PANDING (5)
#define TITLT_IMG_HEIGHT (55)
#define TITLE_LABEL_HEIGHT (15)
#define TITLE_LABEL_TOP_PANDING (13)
#define CREAT_BY_LABEL_HEIGHT (13)
#define CREAT_BY_LABEL_LEFT_PANDING (20)
#define CREAT_TIME_LABEL_LEFT_PANDING (self.width/2)
#define CREAT_BY_LABEL_INNER (15)
#define CREAT_BY_VALUE_LABEL_INNER (5)
#define TEXTVIEW_BOTTOM_PANDING (20)
#import "ICRAnnouncementDetailHeadView.h"
#import "ICRAnnocementContentView.h"
#import "ICRAnnouncement.h"
@interface ICRAnnouncementDetailHeadView ()
@property (strong, nonatomic) UIImageView *m_titleImageView;
@property (strong, nonatomic) UILabel *m_titleLabel;
@property (strong, nonatomic) UILabel *m_creatByLabel;
@property (strong, nonatomic) UILabel *m_creatByValueLabel;
@property (strong, nonatomic) UILabel *m_creatTimeLabel;
@property (strong, nonatomic) UILabel *m_creatTimeValueLabel;
@property (strong, nonatomic) UILabel *m_announcementContentLabel;
@property (strong, nonatomic) UILabel *m_announcementContentDetail;
@end
@implementation ICRAnnouncementDetailHeadView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// code
[self _init];
}
return self;
}
- (void)layoutSubviews {
CGFloat fMaxW = self.width - CREAT_BY_LABEL_LEFT_PANDING;
CGSize size = CGSizeMake( fMaxW , CGFLOAT_MAX );
size = [_m_titleLabel widthLimitedSizeThatFits:size];
_m_titleImageView.frame = (CGRect){
.origin.x = CREAT_BY_LABEL_LEFT_PANDING,
.origin.y = TITLE_IMG_TOP_PANDING,
.size.width = self.width - CREAT_BY_LABEL_LEFT_PANDING * 2,
.size.height = size.height + TITLE_LABEL_TOP_PANDING * 2
};
_m_titleLabel.frame = (CGRect){
.origin.x = (_m_titleImageView.width - size.width)/2,
.origin.y = (_m_titleImageView.height - size.height)/2,
.size = size
};
size = [_m_creatByLabel widthLimitedSizeThatFits:LIMITED_SIZE];
_m_creatByLabel.frame = (CGRect){
.origin.x = _m_titleImageView.left,
.origin.y = _m_titleImageView.bottom + CREAT_BY_LABEL_INNER,
.size = size
};
size = [_m_creatByValueLabel widthLimitedSizeThatFits:LIMITED_SIZE];
_m_creatByValueLabel.frame = (CGRect){
.origin.x = _m_creatByLabel.left,
.origin.y = _m_creatByLabel.bottom + CREAT_BY_VALUE_LABEL_INNER,
.size = size
};
size = [_m_creatTimeLabel widthLimitedSizeThatFits:LIMITED_SIZE];
_m_creatTimeLabel.frame = (CGRect){
.origin.x = CREAT_TIME_LABEL_LEFT_PANDING,
.origin.y = _m_creatByLabel.top,
.size = size
};
size = [_m_creatTimeValueLabel widthLimitedSizeThatFits:LIMITED_SIZE];
_m_creatTimeValueLabel.frame = (CGRect){
.origin.x = _m_creatTimeLabel.left,
.origin.y = _m_creatByValueLabel.top,
.size = size
};
size = [_m_announcementContentLabel widthLimitedSizeThatFits:LIMITED_SIZE];
_m_announcementContentLabel.frame = (CGRect){
.origin.x = _m_creatByLabel.left,
.origin.y = _m_creatByValueLabel.bottom + CREAT_BY_LABEL_INNER,
.size = size
};
size = CGSizeMake( fMaxW , CGFLOAT_MAX);
size = [_m_announcementContentDetail heightLimitedSizeThatFits:size];
_m_announcementContentDetail.frame = (CGRect){
.origin.x = _m_announcementContentLabel.left,
.origin.y = _m_announcementContentLabel.bottom + CREAT_BY_VALUE_LABEL_INNER,
.size.width = fMaxW,
.size.height = size.height
};
self.height = _m_announcementContentDetail.bottom + TEXTVIEW_BOTTOM_PANDING;
}
#pragma mark - Private Method
- (void)_init {
self.backgroundColor = MYSELF_BACKGROUND_COLOR;
self.m_titleImageView = [[UIImageView alloc] init];
_m_titleImageView.backgroundColor = [UIColor clearColor];
_m_titleImageView.image = [[UIImage imageNamed:@"AnnounceTitleBG"]
stretchableImageWithLeftCapWidth:50 topCapHeight:10];
[self addSubview:_m_titleImageView];
self.m_titleLabel = [[ICRAnnocementContentView class]
creatLabelWithTextColor:[UIColor whiteColor]
textFont:[UIFont boldSystemFontOfSize:14]
textAlignment:NSTextAlignmentLeft];
_m_titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
_m_titleLabel.numberOfLines = 0;
[_m_titleImageView addSubview:_m_titleLabel];
self.m_creatByLabel = [[ICRAnnocementContentView class]
creatLabelWithTextColor:LABEL_TEXT_COLOR
textFont:[UIFont systemFontOfSize:12]
textAlignment:NSTextAlignmentLeft];
_m_creatByLabel.text = [IBTCommon localizableString:@"Publisher"];
[self addSubview:_m_creatByLabel];
self.m_creatByValueLabel = [[ICRAnnocementContentView class]
creatLabelWithTextColor:CONTENT_LABEL_TEXT_COLOR
textFont:[UIFont systemFontOfSize:14]
textAlignment:NSTextAlignmentLeft];
[self addSubview:_m_creatByValueLabel];
self.m_creatTimeLabel = [[ICRAnnocementContentView class]
creatLabelWithTextColor:LABEL_TEXT_COLOR
textFont:[UIFont systemFontOfSize:12]
textAlignment:NSTextAlignmentLeft];
_m_creatTimeLabel.text = [IBTCommon localizableString:@"Publish Time"];
[self addSubview:_m_creatTimeLabel];
self.m_creatTimeValueLabel = [[ICRAnnocementContentView class]
creatLabelWithTextColor:CONTENT_LABEL_TEXT_COLOR
textFont:[UIFont systemFontOfSize:14]
textAlignment:NSTextAlignmentLeft];
[self addSubview:_m_creatTimeValueLabel];
self.m_announcementContentLabel = [[ICRAnnocementContentView class]
creatLabelWithTextColor:LABEL_TEXT_COLOR
textFont:[UIFont systemFontOfSize:12]
textAlignment:NSTextAlignmentLeft];
_m_announcementContentLabel.text = [IBTCommon localizableString:@"Content"];
[self addSubview:_m_announcementContentLabel];
self.m_announcementContentDetail = [[ICRAnnocementContentView class]
creatLabelWithTextColor:CONTENT_LABEL_TEXT_COLOR
textFont:[UIFont systemFontOfSize:12]
textAlignment:NSTextAlignmentLeft];
_m_announcementContentDetail.numberOfLines = 0;
[self addSubview:_m_announcementContentDetail];
}
#pragma mark - Public Method
- (void)updateContentWithData:(ICRAnnouncement *)announcement {
self.m_titleLabel.text = announcement.title ? : @"";
self.m_creatByValueLabel.text = [announcement createInfo][@"operator"][@"operName"] ? : @"";
self.m_creatTimeValueLabel.text = [announcement createInfo][@"time"] ? :@"";
self.m_announcementContentDetail.text = announcement.content ? : @"";
[self setNeedsLayout];
}
@end