@@ -10,10 +10,10 @@ import UIKit
1010
1111/// A LinkedIn feed item that is implemented with manual layout code.
1212class FeedItemManualView : UIView , DataBinder {
13+ let hMargin : CGFloat = 8
1314
1415 let actionLabel : UILabel = {
1516 let l = UILabel ( )
16- l. backgroundColor = UIColor . blue
1717 return l
1818 } ( )
1919
@@ -33,15 +33,24 @@ class FeedItemManualView: UIView, DataBinder {
3333 return i
3434 } ( )
3535
36- let posterNameLabel : UILabel = UILabel ( )
36+ let posterNameLabel : UILabel = {
37+ let l = UILabel ( )
38+ l. backgroundColor = UIColor . yellow
39+ return l
40+ } ( )
3741
3842 let posterHeadlineLabel : UILabel = {
3943 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
4151 return l
4252 } ( )
4353
44- let posterTimeLabel : UILabel = UILabel ( )
4554 let posterCommentLabel : UILabel = UILabel ( )
4655
4756 let contentImageView : UIImageView = {
@@ -57,23 +66,23 @@ class FeedItemManualView: UIView, DataBinder {
5766
5867 let likeLabel : UILabel = {
5968 let l = UILabel ( )
60- l. backgroundColor = UIColor ( red : 0 , green : 0.9 , blue : 0 , alpha : 1 )
69+ l. backgroundColor = . green
6170 l. text = " Like "
6271 return l
6372 } ( )
6473
6574 let commentLabel : UILabel = {
6675 let l = UILabel ( )
6776 l. text = " Comment "
68- l. backgroundColor = UIColor ( red : 0 , green : 1.0 , blue : 0 , alpha : 1 )
77+ l. backgroundColor = . green
6978 l. textAlignment = . center
7079 return l
7180 } ( )
7281
7382 let shareLabel : UILabel = {
7483 let l = UILabel ( )
7584 l. text = " Share "
76- l. backgroundColor = UIColor ( red : 0 , green : 0.8 , blue : 0 , alpha : 1 )
85+ l. backgroundColor = . green
7786 l. textAlignment = . right
7887 return l
7988 } ( )
@@ -112,9 +121,16 @@ class FeedItemManualView: UIView, DataBinder {
112121
113122 func setData( _ data: FeedItemData ) {
114123 actionLabel. text = data. actionText
124+
115125 posterNameLabel. text = data. posterName
126+ posterNameLabel. sizeToFit ( )
127+
116128 posterHeadlineLabel. text = data. posterHeadline
129+ posterHeadlineLabel. sizeToFit ( )
130+
117131 posterTimeLabel. text = data. posterTimestamp
132+ posterTimeLabel. sizeToFit ( )
133+
118134 posterCommentLabel. text = data. posterComment
119135 contentTitleLabel. text = data. contentTitle
120136 contentDomainLabel. text = data. contentDomain
@@ -124,57 +140,59 @@ class FeedItemManualView: UIView, DataBinder {
124140
125141 override func layoutSubviews( ) {
126142 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 )
129149 actionLabel. sizeToFit ( )
130150
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 )
132152 posterImageView. sizeToFit ( )
133153
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)
138156
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)
142158
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)
145160
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 )
147162 posterCommentLabel. sizeToFit ( )
148163
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 )
150165 contentImageView. sizeToFit ( )
151166
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 )
153168 contentTitleLabel. sizeToFit ( )
154169
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 )
156171 contentDomainLabel. sizeToFit ( )
157172
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 )
159174 likeLabel. sizeToFit ( )
160175
161176 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)
163178
164179 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)
166181
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 )
168183 actorImageView. sizeToFit ( )
169184
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 )
171189 actorCommentLabel. sizeToFit ( )
172190 }
173191
174192 override func sizeThatFits( _ size: CGSize ) -> CGSize {
175193 frame = CGRect ( x: 0 , y: 0 , width: size. width, height: size. height)
176194 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 )
178196 }
179197
180198 override var intrinsicContentSize : CGSize {
0 commit comments