@@ -10,10 +10,10 @@ import UIKit
10
10
11
11
/// A LinkedIn feed item that is implemented with manual layout code.
12
12
class FeedItemManualView : UIView , DataBinder {
13
+ let hMargin : CGFloat = 8
13
14
14
15
let actionLabel : UILabel = {
15
16
let l = UILabel ( )
16
- l. backgroundColor = UIColor . blue
17
17
return l
18
18
} ( )
19
19
@@ -33,15 +33,24 @@ class FeedItemManualView: UIView, DataBinder {
33
33
return i
34
34
} ( )
35
35
36
- let posterNameLabel : UILabel = UILabel ( )
36
+ let posterNameLabel : UILabel = {
37
+ let l = UILabel ( )
38
+ l. backgroundColor = UIColor . yellow
39
+ return l
40
+ } ( )
37
41
38
42
let posterHeadlineLabel : UILabel = {
39
43
let l = UILabel ( )
40
- l. numberOfLines = 3
44
+ l. backgroundColor = UIColor . yellow
45
+ return l
46
+ } ( )
47
+
48
+ let posterTimeLabel : UILabel = {
49
+ let l = UILabel ( )
50
+ l. backgroundColor = UIColor . yellow
41
51
return l
42
52
} ( )
43
53
44
- let posterTimeLabel : UILabel = UILabel ( )
45
54
let posterCommentLabel : UILabel = UILabel ( )
46
55
47
56
let contentImageView : UIImageView = {
@@ -57,23 +66,23 @@ class FeedItemManualView: UIView, DataBinder {
57
66
58
67
let likeLabel : UILabel = {
59
68
let l = UILabel ( )
60
- l. backgroundColor = UIColor ( red : 0 , green : 0.9 , blue : 0 , alpha : 1 )
69
+ l. backgroundColor = . green
61
70
l. text = " Like "
62
71
return l
63
72
} ( )
64
73
65
74
let commentLabel : UILabel = {
66
75
let l = UILabel ( )
67
76
l. text = " Comment "
68
- l. backgroundColor = UIColor ( red : 0 , green : 1.0 , blue : 0 , alpha : 1 )
77
+ l. backgroundColor = . green
69
78
l. textAlignment = . center
70
79
return l
71
80
} ( )
72
81
73
82
let shareLabel : UILabel = {
74
83
let l = UILabel ( )
75
84
l. text = " Share "
76
- l. backgroundColor = UIColor ( red : 0 , green : 0.8 , blue : 0 , alpha : 1 )
85
+ l. backgroundColor = . green
77
86
l. textAlignment = . right
78
87
return l
79
88
} ( )
@@ -112,9 +121,16 @@ class FeedItemManualView: UIView, DataBinder {
112
121
113
122
func setData( _ data: FeedItemData ) {
114
123
actionLabel. text = data. actionText
124
+
115
125
posterNameLabel. text = data. posterName
126
+ posterNameLabel. sizeToFit ( )
127
+
116
128
posterHeadlineLabel. text = data. posterHeadline
129
+ posterHeadlineLabel. sizeToFit ( )
130
+
117
131
posterTimeLabel. text = data. posterTimestamp
132
+ posterTimeLabel. sizeToFit ( )
133
+
118
134
posterCommentLabel. text = data. posterComment
119
135
contentTitleLabel. text = data. contentTitle
120
136
contentDomainLabel. text = data. contentDomain
@@ -124,57 +140,59 @@ class FeedItemManualView: UIView, DataBinder {
124
140
125
141
override func layoutSubviews( ) {
126
142
super. layoutSubviews ( )
127
- optionsLabel. frame = CGRect ( x: bounds. width- optionsLabel. frame. width, y: 0 , width: optionsLabel. frame. width, height: optionsLabel. frame. height)
128
- actionLabel. frame = CGRect ( x: 0 , y: 0 , width: bounds. width- optionsLabel. frame. width, height: 0 )
143
+
144
+ let vMargin : CGFloat = 4
145
+ let spacing : CGFloat = 1
146
+
147
+ optionsLabel. frame = CGRect ( x: bounds. width- optionsLabel. frame. width - hMargin, y: hMargin, width: optionsLabel. frame. width, height: optionsLabel. frame. height)
148
+ actionLabel. frame = CGRect ( x: hMargin, y: hMargin, width: bounds. width- optionsLabel. frame. width, height: 0 )
129
149
actionLabel. sizeToFit ( )
130
150
131
- posterImageView. frame = CGRect ( x: 0 , y: actionLabel. frame. bottom, width: posterImageView. frame. width, height: 0 )
151
+ posterImageView. frame = CGRect ( x: hMargin , y: actionLabel. frame. bottom + 10 , width: posterImageView. frame. width, height: 0 )
132
152
posterImageView. sizeToFit ( )
133
153
134
- let contentInsets = UIEdgeInsets ( top: 0 , left: 1 , bottom: 2 , right: 3 )
135
- let posterLabelWidth = bounds. width- posterImageView. frame. width - contentInsets. left - contentInsets. right
136
- posterNameLabel. frame = CGRect ( x: posterImageView. frame. right + contentInsets. left, y: posterImageView. frame. origin. y + contentInsets. top, width: posterLabelWidth, height: 0 )
137
- posterNameLabel. sizeToFit ( )
154
+ let contentInsets = UIEdgeInsets ( top: - 10 , left: 2 , bottom: 2 , right: 3 )
155
+ posterNameLabel. frame = CGRect ( x: posterImageView. frame. right + contentInsets. left, y: posterImageView. frame. origin. y + contentInsets. top, width: posterNameLabel. frame. width, height: posterNameLabel. frame. height)
138
156
139
- let spacing : CGFloat = 1
140
- posterHeadlineLabel. frame = CGRect ( x: posterImageView. frame. right + contentInsets. left, y: posterNameLabel. frame. bottom + spacing, width: posterLabelWidth, height: 0 )
141
- posterHeadlineLabel. sizeToFit ( )
157
+ posterHeadlineLabel. frame = CGRect ( x: posterImageView. frame. right + contentInsets. left, y: posterNameLabel. frame. bottom + spacing, width: posterHeadlineLabel. frame. width, height: posterHeadlineLabel. frame. height)
142
158
143
- posterTimeLabel. frame = CGRect ( x: posterImageView. frame. right + contentInsets. left, y: posterHeadlineLabel. frame. bottom + spacing, width: posterLabelWidth, height: 0 )
144
- posterTimeLabel. sizeToFit ( )
159
+ posterTimeLabel. frame = CGRect ( x: posterImageView. frame. right + contentInsets. left, y: posterHeadlineLabel. frame. bottom + spacing, width: posterTimeLabel. frame. width, height: posterTimeLabel. frame. height)
145
160
146
- posterCommentLabel. frame = CGRect ( x: 0 , y: max ( posterImageView. frame. bottom, posterTimeLabel. frame. bottom + contentInsets. bottom) , width: frame. width, height: 0 )
161
+ posterCommentLabel. frame = CGRect ( x: hMargin , y: max ( posterImageView. frame. bottom, posterTimeLabel. frame. bottom + contentInsets. bottom) , width: frame. width, height: 0 )
147
162
posterCommentLabel. sizeToFit ( )
148
163
149
- contentImageView. frame = CGRect ( x: frame . width / 2 - contentImageView . frame . width / 2 , y: posterCommentLabel. frame. bottom, width: frame. width, height: 0 )
164
+ contentImageView. frame = CGRect ( x: hMargin , y: posterCommentLabel. frame. bottom, width: frame. width, height: 0 )
150
165
contentImageView. sizeToFit ( )
151
166
152
- contentTitleLabel. frame = CGRect ( x: 0 , y: contentImageView. frame. bottom, width: frame. width, height: 0 )
167
+ contentTitleLabel. frame = CGRect ( x: hMargin , y: contentImageView. frame. bottom, width: frame. width, height: 0 )
153
168
contentTitleLabel. sizeToFit ( )
154
169
155
- contentDomainLabel. frame = CGRect ( x: 0 , y: contentTitleLabel. frame. bottom, width: frame. width, height: 0 )
170
+ contentDomainLabel. frame = CGRect ( x: hMargin , y: contentTitleLabel. frame. bottom, width: frame. width, height: 0 )
156
171
contentDomainLabel. sizeToFit ( )
157
172
158
- likeLabel. frame = CGRect ( x: 0 , y: contentDomainLabel. frame. bottom, width: 0 , height: 0 )
173
+ likeLabel. frame = CGRect ( x: hMargin , y: contentDomainLabel. frame. bottom + vMargin , width: 0 , height: 0 )
159
174
likeLabel. sizeToFit ( )
160
175
161
176
commentLabel. sizeToFit ( )
162
- commentLabel. frame = CGRect ( x: frame. width/ 2 - commentLabel. frame. width/ 2 , y: contentDomainLabel. frame. bottom, width: commentLabel. frame. width, height: commentLabel. frame. height)
177
+ commentLabel. frame = CGRect ( x: frame. width / 2 - commentLabel. frame. width / 2 , y: contentDomainLabel. frame. bottom + vMargin , width: commentLabel. frame. width, height: commentLabel. frame. height)
163
178
164
179
shareLabel. sizeToFit ( )
165
- shareLabel. frame = CGRect ( x: frame. width- shareLabel. frame. width, y: contentDomainLabel. frame. bottom, width: shareLabel. frame. width, height: shareLabel. frame. height)
180
+ shareLabel. frame = CGRect ( x: frame. width - shareLabel. frame. width - hMargin , y: contentDomainLabel. frame. bottom + vMargin , width: shareLabel. frame. width, height: shareLabel. frame. height)
166
181
167
- actorImageView. frame = CGRect ( x: 0 , y: likeLabel. frame. bottom, width: 0 , height: 0 )
182
+ actorImageView. frame = CGRect ( x: hMargin , y: likeLabel. frame. bottom + vMargin , width: 0 , height: 0 )
168
183
actorImageView. sizeToFit ( )
169
184
170
- actorCommentLabel. frame = CGRect ( x: actorImageView. frame. right, y: likeLabel. frame. bottom, width: frame. width- actorImageView. frame. width, height: 0 )
185
+ actorCommentLabel. frame = CGRect ( x: actorImageView. frame. right + vMargin,
186
+ y: actorImageView. frame. minY + ( actorImageView. frame. height - actorCommentLabel. frame. height) / 2 ,
187
+ width: frame. width- actorImageView. frame. width,
188
+ height: 0 )
171
189
actorCommentLabel. sizeToFit ( )
172
190
}
173
191
174
192
override func sizeThatFits( _ size: CGSize ) -> CGSize {
175
193
frame = CGRect ( x: 0 , y: 0 , width: size. width, height: size. height)
176
194
layoutSubviews ( )
177
- return CGSize ( width: size. width, height: max ( actorImageView. frame. bottom, actorCommentLabel. frame. bottom) )
195
+ return CGSize ( width: size. width, height: max ( actorImageView. frame. bottom, actorCommentLabel. frame. bottom) + hMargin )
178
196
}
179
197
180
198
override var intrinsicContentSize : CGSize {
0 commit comments