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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
//
// QuestionDescribeCell.m
// redstar
//
// Created by admin on 15/11/3.
// Copyright © 2015年 ZWF. All rights reserved.
//
#import "QuestionDescribeCell.h"
#import <UIImageView+WebCache.h>
@interface QuestionDescribeCell ()
@property (nonatomic, strong) NSLayoutConstraint *picConstraint;
@end
@implementation QuestionDescribeCell
#pragma mark - System Methods
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self setup];
}
return self;
}
#pragma mark - Private Methods
- (void)setup
{
self.titleLabel.textColor = kDetailCellDescribeTextColor;
_titleLabel.text = @"问题与建议描述";
self.pictureLabel.textColor = kDetailCellDescribeTextColor;
_pictureLabel.text = @"照片";
self.pictureView.backgroundColor = [UIColor whiteColor];
self.feedbackLabel.textColor = kDetailCellDescribeTextColor;
self.feedbackBackView.backgroundColor = kQuestionFeedBackColor;
}
- (void)setQuestionDetail:(QuestionDetailModel *)questionDetail
{
_questionDetail = questionDetail;
// 问题与描述
NSString *describeStr = [NSString stringWithFormat:@"%@", questionDetail.content];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:describeStr];
NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
paragraphStyle1.alignment = NSTextAlignmentLeft;
paragraphStyle1.lineSpacing = 6; //行自定义行高度
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [describeStr length])];
self.describeLabel.attributedText = attributedString;
self.pictureView.backgroundColor = [UIColor whiteColor];
CGFloat imageMaginX = 20;
CGFloat imageMaginY = 10;
CGFloat imageW = (kScreenWidth - imageMaginX * 3) / 2;
CGFloat imageH = 110;
int count = (int)questionDetail.attachments.count;
int k ;
if (count % 2 == 0) {
k = count / 2;
} else {
k = (count + 1) / 2;
}
self.picConstraint.constant = imageMaginY + (imageMaginY + imageH) * k;
[self.pictureView setNeedsUpdateConstraints];
for (int i = 0; i < count; i++) {
UIImageView *imageView = [[UIImageView alloc] init];
imageView.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *imageDict = questionDetail.attachments[i];
NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kRedStarURL, imageDict[@"fileUrl"]]];
[imageView sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"default_pic"]];
[self.pictureView addSubview:imageView];
int j = 0;
if ((i + 1) % 2 == 0) {
j = count / 2;
} else {
j = (count + 1) / 2;
}
// 顶端
NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.pictureView attribute:NSLayoutAttributeTop multiplier:1.0 constant:imageMaginY + (j - 1) * (imageH + imageMaginY)];
[self.pictureView addConstraint:titleTop];
if ((i + 1) % 2 == 0) {
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.pictureView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:imageMaginX + imageW + imageMaginX];
[self.pictureView addConstraint:titleLeft];
} else {
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.pictureView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:imageMaginX];
[self.pictureView addConstraint:titleLeft];
}
// 右边
NSLayoutConstraint *titleWidth = [NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:imageW];
[self.pictureView addConstraint:titleWidth];
// 高度
NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:imageH];
[self.pictureView addConstraint:titleHeight];
}
// 反馈
if (questionDetail.feedback == nil || questionDetail.feedback == NULL || [questionDetail.feedback isEqual:[NSNull null]]) {
self.answerLabel.text = @"";
} else {
NSString *answerStr = [NSString stringWithFormat:@"%@", questionDetail.feedback];
NSMutableAttributedString *answerAttrStr = [[NSMutableAttributedString alloc] initWithString:answerStr];
NSMutableParagraphStyle *paragraphStyle2 = [[NSMutableParagraphStyle alloc] init];
paragraphStyle2.alignment = NSTextAlignmentLeft;
paragraphStyle2.lineSpacing = 6; //行自定义行高度
[answerAttrStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle2 range:NSMakeRange(0, answerStr.length)];
self.answerLabel.attributedText = answerAttrStr;
}
// 解决人
if (questionDetail.resolveUser_name == nil || questionDetail.resolveUser_name == NULL || [questionDetail.resolveUser_name isEqual:[NSNull null]]) {
self.peopleLabel.text = [NSString stringWithFormat:@"问题解决负责人:"];
} else {
self.peopleLabel.text = [NSString stringWithFormat:@"问题解决负责人:%@", questionDetail.resolveUser_name];
}
if (questionDetail.resolveTime == nil || questionDetail.resolveTime == NULL || [questionDetail.resolveTime isEqual:[NSNull null]]) {
self.dateLabel.text = [NSString stringWithFormat:@"反馈时间:"];
} else {
self.dateLabel.text = [NSString stringWithFormat:@"反馈时间:%@", questionDetail.resolveTime];
}
}
#pragma mark - lazy loading
- (UILabel *)titleLabel
{
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:15.0];
_titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_titleLabel];
// 顶端
NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:10];
[self.contentView addConstraint:titleTop];
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self.contentView addConstraint:titleLeft];
// 右边
NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self.contentView addConstraint:titleRight];
// 高度
NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:25];
[self.contentView addConstraint:titleHeight];
}
return _titleLabel;
}
- (UILabel *)describeLabel
{
if (!_describeLabel) {
_describeLabel = [[UILabel alloc] init];
_describeLabel.textColor = kdetailCellTitleColor;
_describeLabel.font = [UIFont systemFontOfSize:15.0];
_describeLabel.translatesAutoresizingMaskIntoConstraints = NO;
_describeLabel.numberOfLines = 0;
[_describeLabel sizeToFit];
[self.contentView addSubview:_describeLabel];
// 顶端
NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_describeLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.titleLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:5];
[self.contentView addConstraint:titleTop];
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_describeLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self.contentView addConstraint:titleLeft];
// 右边
NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_describeLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self.contentView addConstraint:titleRight];
}
return _describeLabel;
}
- (UILabel *)pictureLabel
{
if (!_pictureLabel) {
_pictureLabel = [[UILabel alloc] init];
_pictureLabel.font = [UIFont systemFontOfSize:15.0];
_pictureLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_pictureLabel];
// 顶端
NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_pictureLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.describeLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:5];
[self.contentView addConstraint:titleTop];
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_pictureLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self.contentView addConstraint:titleLeft];
// 右边
NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_pictureLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self.contentView addConstraint:titleRight];
// 高度
NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_pictureLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30];
[self.contentView addConstraint:titleHeight];
}
return _pictureLabel;
}
- (UIView *)pictureView
{
if (!_pictureView) {
_pictureView = [[UIView alloc] init];
_pictureView.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_pictureView];
// 顶端
NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_pictureView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.pictureLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:5];
[self.contentView addConstraint:titleTop];
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_pictureView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
[self.contentView addConstraint:titleLeft];
// 右边
NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_pictureView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
[self.contentView addConstraint:titleRight];
// 高度
self.picConstraint = [NSLayoutConstraint constraintWithItem:_pictureView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:130];
[self.contentView addConstraint:_picConstraint];
}
return _pictureView;
}
- (UILabel *)feedbackLabel
{
if (!_feedbackLabel) {
_feedbackLabel = [[UILabel alloc] init];
_feedbackLabel.font = [UIFont systemFontOfSize:15.0];
_feedbackLabel.translatesAutoresizingMaskIntoConstraints = NO;
_feedbackLabel.text = @"问题反馈";
[self.contentView addSubview:_feedbackLabel];
// 顶端
NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_feedbackLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.pictureView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:5];
[self.contentView addConstraint:titleTop];
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_feedbackLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self.contentView addConstraint:titleLeft];
// 右边
NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_feedbackLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self.contentView addConstraint:titleRight];
// 高度
NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_feedbackLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30];
[self.contentView addConstraint:titleHeight];
}
return _feedbackLabel;
}
- (UIView *)feedbackBackView
{
if (!_feedbackBackView) {
_feedbackBackView = [[UIView alloc] init];
_feedbackBackView.translatesAutoresizingMaskIntoConstraints = NO;
_feedbackBackView.layer.cornerRadius = 5;
_feedbackBackView.layer.borderWidth = 1;
_feedbackBackView.layer.borderColor = kQuestionFeedBackTitleCGColor;
[self.contentView addSubview:_feedbackBackView];
// 顶端
NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_feedbackBackView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.feedbackLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:5];
[self.contentView addConstraint:titleTop];
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_feedbackBackView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self.contentView addConstraint:titleLeft];
// 右边
NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_feedbackBackView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self.contentView addConstraint:titleRight];
// 高度
NSLayoutConstraint *titleBootom = [NSLayoutConstraint constraintWithItem:_feedbackBackView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-15];
[self.contentView addConstraint:titleBootom];
}
return _feedbackBackView;
}
- (UILabel *)answerLabel
{
if (!_answerLabel) {
_answerLabel = [[UILabel alloc] init];
[_answerLabel sizeToFit];
_answerLabel.font = [UIFont systemFontOfSize:15.0];
_answerLabel.translatesAutoresizingMaskIntoConstraints = NO;
_answerLabel.textColor = kQuestionFeedBackTitleColor;
_answerLabel.numberOfLines = 0;
[self.feedbackBackView addSubview:_answerLabel];
// 顶端
NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_answerLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.feedbackBackView attribute:NSLayoutAttributeTop multiplier:1.0 constant:12];
[self.feedbackBackView addConstraint:titleTop];
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_answerLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.feedbackBackView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10];
[self.feedbackBackView addConstraint:titleLeft];
// 右边
NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_answerLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.feedbackBackView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-10];
[self.feedbackBackView addConstraint:titleRight];
}
return _answerLabel;
}
- (UILabel *)peopleLabel
{
if (!_peopleLabel) {
_peopleLabel = [[UILabel alloc] init];
_peopleLabel.font = [UIFont systemFontOfSize:15.0];
_peopleLabel.translatesAutoresizingMaskIntoConstraints = NO;
_peopleLabel.textColor = kDetailCellDescribeTextColor;
_peopleLabel.numberOfLines = 0;
[self.feedbackBackView addSubview:_peopleLabel];
// 顶端
NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_peopleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.answerLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:5];
[self.feedbackBackView addConstraint:titleTop];
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_peopleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.feedbackBackView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10];
[self.feedbackBackView addConstraint:titleLeft];
// 右边
NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_peopleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.feedbackBackView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-10];
[self.feedbackBackView addConstraint:titleRight];
// 右边
NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_peopleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20];
[self.feedbackBackView addConstraint:titleHeight];
}
return _peopleLabel;
}
- (UILabel *)dateLabel
{
if (!_dateLabel) {
_dateLabel = [[UILabel alloc] init];
_dateLabel.font = [UIFont systemFontOfSize:15.0];
_dateLabel.translatesAutoresizingMaskIntoConstraints = NO;
_dateLabel.textColor = kDetailCellDescribeTextColor;
_dateLabel.numberOfLines = 0;
[self.feedbackBackView addSubview:_dateLabel];
// 顶端
NSLayoutConstraint *titleTop = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.peopleLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[self.feedbackBackView addConstraint:titleTop];
// 左边
NSLayoutConstraint *titleLeft = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.feedbackBackView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10];
[self.feedbackBackView addConstraint:titleLeft];
// 右边
NSLayoutConstraint *titleRight = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.feedbackBackView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-10];
[self.feedbackBackView addConstraint:titleRight];
// 右边
NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20];
[self.feedbackBackView addConstraint:titleHeight];
NSLayoutConstraint *titleBottom = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.feedbackBackView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-10];
[self.feedbackBackView addConstraint:titleBottom];
}
return _dateLabel;
}
@end