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
//
// AnnounceDetailHeadView.m
// redstar
//
// Created by admin on 15/11/30.
// Copyright © 2015年 ZWF. All rights reserved.
//
#import "AnnounceDetailHeadView.h"
@interface AnnounceDetailHeadView ()
@property (nonatomic, strong) UIImageView *bannerImageView;
@property (nonatomic, strong) UILabel *peopleLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@end
@implementation AnnounceDetailHeadView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (void)setup
{
UIImage *image = [UIImage imageNamed:@"anno_banner"];
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 50, 30) resizingMode:UIImageResizingModeStretch];
self.bannerImageView.image = image;
self.peopleLabel.text = @"发布人";
self.dateLabel.text = @"发布日期";
}
- (void)setAnnoDetail:(AnnounceDetailModel *)annoDetail
{
_annoDetail = annoDetail;
self.titleLabel.text = [NSString stringWithFormat:@"%@", _annoDetail.title];
self.nameLabel.text = [NSString stringWithFormat:@"%@", _annoDetail.lastModify_operName];
self.timeLabel.text = [NSString stringWithFormat:@"%@", _annoDetail.lastModify_time];
}
- (UIImageView *)bannerImageView
{
if (!_bannerImageView) {
_bannerImageView = [[UIImageView alloc] init];
_bannerImageView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_bannerImageView];
NSLayoutConstraint *contentTop = [NSLayoutConstraint constraintWithItem:_bannerImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
[self addConstraint:contentTop];
NSLayoutConstraint *contentLeft = [NSLayoutConstraint constraintWithItem:_bannerImageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self addConstraint:contentLeft];
NSLayoutConstraint *contentRight = [NSLayoutConstraint constraintWithItem:_bannerImageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self addConstraint:contentRight];
NSLayoutConstraint *contentHeight = [NSLayoutConstraint constraintWithItem:_bannerImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:54];
[self addConstraint:contentHeight];
}
return _bannerImageView;
}
- (UILabel *)titleLabel
{
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.font = [UIFont systemFontOfSize:16.0];
_titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.bannerImageView addSubview:_titleLabel];
NSLayoutConstraint *contentTop = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.bannerImageView attribute:NSLayoutAttributeTop multiplier:1.0 constant:2];
[self.bannerImageView addConstraint:contentTop];
NSLayoutConstraint *contentLeft = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.bannerImageView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self.bannerImageView addConstraint:contentLeft];
NSLayoutConstraint *contentRight = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.bannerImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self.bannerImageView addConstraint:contentRight];
NSLayoutConstraint *contentHeight = [NSLayoutConstraint constraintWithItem:_titleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:44];
[self.bannerImageView addConstraint:contentHeight];
}
return _titleLabel;
}
- (UILabel *)peopleLabel
{
if (!_peopleLabel) {
_peopleLabel = [[UILabel alloc] init];
_peopleLabel.textColor = kNavigationBarColor;
_peopleLabel.font = [UIFont systemFontOfSize:13.0];
_peopleLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_peopleLabel];
NSLayoutConstraint *contentTop = [NSLayoutConstraint constraintWithItem:_peopleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.bannerImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:12];
[self addConstraint:contentTop];
NSLayoutConstraint *contentLeft = [NSLayoutConstraint constraintWithItem:_peopleLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self addConstraint:contentLeft];
NSLayoutConstraint *contentWidth = [NSLayoutConstraint constraintWithItem:_peopleLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:50];
[self addConstraint:contentWidth];
NSLayoutConstraint *contentHeight = [NSLayoutConstraint constraintWithItem:_peopleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20];
[self addConstraint:contentHeight];
}
return _peopleLabel;
}
- (UILabel *)dateLabel
{
if (!_dateLabel) {
_dateLabel = [[UILabel alloc] init];
_dateLabel.textColor = kNavigationBarColor;
_dateLabel.font = [UIFont systemFontOfSize:13.0];
_dateLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_dateLabel];
NSLayoutConstraint *contentTop = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.bannerImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:12];
[self addConstraint:contentTop];
NSLayoutConstraint *contentLeft = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
[self addConstraint:contentLeft];
NSLayoutConstraint *contentWidth = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:80];
[self addConstraint:contentWidth];
NSLayoutConstraint *contentHeight = [NSLayoutConstraint constraintWithItem:_dateLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20];
[self addConstraint:contentHeight];
}
return _dateLabel;
}
- (UILabel *)nameLabel
{
if (!_nameLabel) {
_nameLabel = [[UILabel alloc] init];
_nameLabel.textColor = kLightBlack;
_nameLabel.font = [UIFont systemFontOfSize:15.0];
_nameLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_nameLabel];
NSLayoutConstraint *contentTop = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.peopleLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:1];
[self addConstraint:contentTop];
NSLayoutConstraint *contentLeft = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self addConstraint:contentLeft];
NSLayoutConstraint *contentRight = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:20];
[self addConstraint:contentRight];
NSLayoutConstraint *contentHeight = [NSLayoutConstraint constraintWithItem:_nameLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20];
[self addConstraint:contentHeight];
}
return _nameLabel;
}
- (UILabel *)timeLabel
{
if (!_timeLabel) {
_timeLabel = [[UILabel alloc] init];
_timeLabel.textColor = kLightBlack;
_timeLabel.font = [UIFont systemFontOfSize:15.0];
_timeLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_timeLabel];
NSLayoutConstraint *contentTop = [NSLayoutConstraint constraintWithItem:_timeLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.dateLabel attribute:NSLayoutAttributeBottom multiplier:1.0 constant:1];
[self addConstraint:contentTop];
NSLayoutConstraint *contentLeft = [NSLayoutConstraint constraintWithItem:_timeLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
[self addConstraint:contentLeft];
NSLayoutConstraint *contentRight = [NSLayoutConstraint constraintWithItem:_timeLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self addConstraint:contentRight];
NSLayoutConstraint *contentHeight = [NSLayoutConstraint constraintWithItem:_timeLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20];
[self addConstraint:contentHeight];
}
return _timeLabel;
}
@end