@@ -10,162 +10,162 @@ import NKFrameLayoutKit
1010
1111/// A LinkedIn feed item that is implemented with NKFrameLayoutKit code.
1212class NKFrameLayoutKitView : UIView , DataBinder {
13-
14- var mainFrameLayout : NKGridFrameLayout !
15-
16- let actionLabel : UILabel = {
17- let l = UILabel ( )
18- l. backgroundColor = UIColor . blue
19- return l
20- } ( )
21-
22- let optionsLabel : UILabel = {
23- let l = UILabel ( )
24- l. text = " ... "
25- return l
26- } ( )
27-
28- let posterImageView : UIImageView = {
29- let i = UIImageView ( )
30- i. image = UIImage ( named: " 50x50.png " )
31- i. backgroundColor = UIColor . orange
32- i. contentMode = . scaleToFill
33- return i
34- } ( )
35-
36- let posterNameLabel : UILabel = UILabel ( )
37-
38- let posterHeadlineLabel : UILabel = {
39- let l = UILabel ( )
40- l. numberOfLines = 3
41- return l
42- } ( )
43-
44- let posterTimeLabel : UILabel = UILabel ( )
45- let posterCommentLabel : UILabel = UILabel ( )
46-
47- let contentImageView : UIImageView = {
48- let i = UIImageView ( )
49- i. image = UIImage ( named: " 350x200.png " )
50- i. contentMode = . scaleToFill
51- return i
52- } ( )
53-
54- let contentTitleLabel : UILabel = UILabel ( )
55- let contentDomainLabel : UILabel = UILabel ( )
56-
57- let likeLabel : UILabel = {
58- let l = UILabel ( )
59- l. backgroundColor = UIColor ( red: 0 , green: 0.9 , blue: 0 , alpha: 1 )
60- l. text = " Like "
61- return l
62- } ( )
63-
64- let commentLabel : UILabel = {
65- let l = UILabel ( )
66- l. text = " Comment "
67- l. backgroundColor = UIColor ( red: 0 , green: 1.0 , blue: 0 , alpha: 1 )
68- l. textAlignment = . center
69- return l
70- } ( )
71-
72- let shareLabel : UILabel = {
73- let l = UILabel ( )
74- l. text = " Share "
75- l. backgroundColor = UIColor ( red: 0 , green: 0.8 , blue: 0 , alpha: 1 )
76- l. textAlignment = . right
77- return l
78- } ( )
79-
80- let actorImageView : UIImageView = {
81- let i = UIImageView ( )
82- i. image = UIImage ( named: " 50x50.png " )
83- return i
84- } ( )
85-
86- let actorCommentLabel : UILabel = UILabel ( )
87-
88- lazy var topBar : NKDoubleFrameLayout = {
89- let v = NKDoubleFrameLayout ( direction: . horizontal, andViews: [ self . actionLabel, self . optionsLabel] ) !
90- v. rightFrameLayout. contentHorizontalAlignment = . right
91- return v
92- } ( )
93-
94- lazy var posters : NKDoubleFrameLayout = {
95- let labels = NKGridFrameLayout ( direction: . vertical, andViews: [ self . posterNameLabel, self . posterHeadlineLabel, self . posterTimeLabel] ) !
96- labels. edgeInsets = UIEdgeInsets ( top: 1 , left: 2 , bottom: 3 , right: 4 )
97-
98- let v = NKDoubleFrameLayout ( direction: . horizontal, andViews: [ self . posterImageView, labels] ) !
99- v. leftFrameLayout. contentVerticalAlignment = . center
100- v. spacing = 1
101- return v
102- } ( )
103-
104- lazy var actions : NKGridFrameLayout = {
105- let v = NKGridFrameLayout ( direction: . horizontal) ! // andViews: [self.likeLabel, self.commentLabel, self.shareLabel]
106- v. add ( withTargetView: self . likeLabel) . contentHorizontalAlignment = . left
107- v. add ( withTargetView: self . commentLabel) . contentHorizontalAlignment = . center
108- v. add ( withTargetView: self . shareLabel) . contentHorizontalAlignment = . right
109- v. layoutAlignment = . split
110- return v
111- } ( )
112-
113- lazy var comment : NKDoubleFrameLayout = {
114- let v = NKDoubleFrameLayout ( direction: . horizontal, andViews: [ self . actorImageView, self . actorCommentLabel] ) !
115- return v
116- } ( )
117-
118- override init ( frame: CGRect ) {
119- super. init ( frame: frame)
120- addSubview ( actionLabel)
121- addSubview ( optionsLabel)
122- addSubview ( posterImageView)
123- addSubview ( posterNameLabel)
124- addSubview ( posterHeadlineLabel)
125- addSubview ( posterTimeLabel)
126- addSubview ( posterCommentLabel)
127- addSubview ( contentImageView)
128- addSubview ( contentTitleLabel)
129- addSubview ( contentDomainLabel)
130- addSubview ( likeLabel)
131- addSubview ( commentLabel)
132- addSubview ( shareLabel)
133- addSubview ( actorImageView)
134- addSubview ( actorCommentLabel)
135- backgroundColor = UIColor . white
136-
137- mainFrameLayout = NKGridFrameLayout ( direction: . vertical, andViews: [ topBar, posters, posterCommentLabel, contentImageView, contentTitleLabel, contentDomainLabel, actions, comment] )
138- mainFrameLayout. edgeInsets = UIEdgeInsets ( top: 5 , left: 5 , bottom: 5 , right: 5 )
139- addSubview ( mainFrameLayout)
140- }
141-
142- required init ? ( coder aDecoder: NSCoder ) {
143- fatalError ( " init(coder:) has not been implemented " )
144- }
145-
146- func setData( _ data: FeedItemData ) {
147- actionLabel. text = data. actionText
148- posterNameLabel. text = data. posterName
149- posterHeadlineLabel. text = data. posterHeadline
150- posterTimeLabel. text = data. posterTimestamp
151- posterCommentLabel. text = data. posterComment
152- contentTitleLabel. text = data. contentTitle
153- contentDomainLabel. text = data. contentDomain
154- actorCommentLabel. text = data. actorComment
155- setNeedsLayout ( )
156- }
157-
158- override func layoutSubviews( ) {
159- super. layoutSubviews ( )
160- mainFrameLayout. frame = self . bounds
161- }
162-
163- override func sizeThatFits( _ size: CGSize ) -> CGSize {
164- return mainFrameLayout. sizeThatFits ( size)
165- }
166-
167- override var intrinsicContentSize : CGSize {
168- return mainFrameLayout. sizeThatFits ( CGSize ( width: frame. width, height: CGFloat . greatestFiniteMagnitude) )
169- }
13+
14+ var mainFrameLayout : NKGridFrameLayout !
15+
16+ let actionLabel : UILabel = {
17+ let l = UILabel ( )
18+ l. backgroundColor = UIColor . blue
19+ return l
20+ } ( )
21+
22+ let optionsLabel : UILabel = {
23+ let l = UILabel ( )
24+ l. text = " ... "
25+ return l
26+ } ( )
27+
28+ let posterImageView : UIImageView = {
29+ let i = UIImageView ( )
30+ i. image = UIImage ( named: " 50x50.png " )
31+ i. backgroundColor = UIColor . orange
32+ i. contentMode = . scaleToFill
33+ return i
34+ } ( )
35+
36+ let posterNameLabel : UILabel = UILabel ( )
37+
38+ let posterHeadlineLabel : UILabel = {
39+ let l = UILabel ( )
40+ l. numberOfLines = 3
41+ return l
42+ } ( )
43+
44+ let posterTimeLabel : UILabel = UILabel ( )
45+ let posterCommentLabel : UILabel = UILabel ( )
46+
47+ let contentImageView : UIImageView = {
48+ let i = UIImageView ( )
49+ i. image = UIImage ( named: " 350x200.png " )
50+ i. contentMode = . scaleToFill
51+ return i
52+ } ( )
53+
54+ let contentTitleLabel : UILabel = UILabel ( )
55+ let contentDomainLabel : UILabel = UILabel ( )
56+
57+ let likeLabel : UILabel = {
58+ let l = UILabel ( )
59+ l. backgroundColor = UIColor ( red: 0 , green: 0.9 , blue: 0 , alpha: 1 )
60+ l. text = " Like "
61+ return l
62+ } ( )
63+
64+ let commentLabel : UILabel = {
65+ let l = UILabel ( )
66+ l. text = " Comment "
67+ l. backgroundColor = UIColor ( red: 0 , green: 1.0 , blue: 0 , alpha: 1 )
68+ l. textAlignment = . center
69+ return l
70+ } ( )
71+
72+ let shareLabel : UILabel = {
73+ let l = UILabel ( )
74+ l. text = " Share "
75+ l. backgroundColor = UIColor ( red: 0 , green: 0.8 , blue: 0 , alpha: 1 )
76+ l. textAlignment = . right
77+ return l
78+ } ( )
79+
80+ let actorImageView : UIImageView = {
81+ let i = UIImageView ( )
82+ i. image = UIImage ( named: " 50x50.png " )
83+ return i
84+ } ( )
85+
86+ let actorCommentLabel : UILabel = UILabel ( )
87+
88+ lazy var topBar : NKDoubleFrameLayout = {
89+ let v = NKDoubleFrameLayout ( direction: . horizontal, andViews: [ self . actionLabel, self . optionsLabel] ) !
90+ v. rightFrameLayout. contentHorizontalAlignment = . right
91+ return v
92+ } ( )
93+
94+ lazy var posters : NKDoubleFrameLayout = {
95+ let labels = NKGridFrameLayout ( direction: . vertical, andViews: [ self . posterNameLabel, self . posterHeadlineLabel, self . posterTimeLabel] ) !
96+ let v = NKDoubleFrameLayout ( direction: . horizontal, andViews: [ self . posterImageView, labels] ) !
97+ v. leftFrameLayout. contentVerticalAlignment = . center
98+ v. spacing = 5
99+ v. edgeInsets = UIEdgeInsets ( top: 5 , left: 0 , bottom: 0 , right: 0 )
100+ return v
101+ } ( )
102+
103+ lazy var actions : NKGridFrameLayout = {
104+ let v = NKGridFrameLayout ( direction: . horizontal) ! // andViews: [self.likeLabel, self.commentLabel, self.shareLabel]
105+ v. add ( withTargetView: self . likeLabel) . contentHorizontalAlignment = . left
106+ v. add ( withTargetView: self . commentLabel) . contentHorizontalAlignment = . center
107+ v. add ( withTargetView: self . shareLabel) . contentHorizontalAlignment = . right
108+ v. layoutAlignment = . split
109+ return v
110+ } ( )
111+
112+ lazy var comment : NKDoubleFrameLayout = {
113+ let v = NKDoubleFrameLayout ( direction: . horizontal, andViews: [ self . actorImageView, self . actorCommentLabel] ) !
114+ v. edgeInsets = UIEdgeInsets ( top: 5 , left: 0 , bottom: 0 , right: 0 )
115+ v. spacing = 5
116+ return v
117+ } ( )
118+
119+ override init ( frame: CGRect ) {
120+ super. init ( frame: frame)
121+ addSubview ( actionLabel)
122+ addSubview ( optionsLabel)
123+ addSubview ( posterImageView)
124+ addSubview ( posterNameLabel)
125+ addSubview ( posterHeadlineLabel)
126+ addSubview ( posterTimeLabel)
127+ addSubview ( posterCommentLabel)
128+ addSubview ( contentImageView)
129+ addSubview ( contentTitleLabel)
130+ addSubview ( contentDomainLabel)
131+ addSubview ( likeLabel)
132+ addSubview ( commentLabel)
133+ addSubview ( shareLabel)
134+ addSubview ( actorImageView)
135+ addSubview ( actorCommentLabel)
136+ backgroundColor = UIColor . white
137+
138+ mainFrameLayout = NKGridFrameLayout ( direction: . vertical, andViews: [ topBar, posters, posterCommentLabel, contentImageView, contentTitleLabel, contentDomainLabel, actions, comment] )
139+ mainFrameLayout. edgeInsets = UIEdgeInsets ( top: 5 , left: 5 , bottom: 5 , right: 5 )
140+ addSubview ( mainFrameLayout)
141+ }
142+
143+ required init ? ( coder aDecoder: NSCoder ) {
144+ fatalError ( " init(coder:) has not been implemented " )
145+ }
146+
147+ func setData( _ data: FeedItemData ) {
148+ actionLabel. text = data. actionText
149+ posterNameLabel. text = data. posterName
150+ posterHeadlineLabel. text = data. posterHeadline
151+ posterTimeLabel. text = data. posterTimestamp
152+ posterCommentLabel. text = data. posterComment
153+ contentTitleLabel. text = data. contentTitle
154+ contentDomainLabel. text = data. contentDomain
155+ actorCommentLabel. text = data. actorComment
156+ setNeedsLayout ( )
157+ }
158+
159+ override func layoutSubviews( ) {
160+ super. layoutSubviews ( )
161+ mainFrameLayout. frame = self . bounds
162+ }
163+
164+ override func sizeThatFits( _ size: CGSize ) -> CGSize {
165+ return mainFrameLayout. sizeThatFits ( size)
166+ }
167+
168+ override var intrinsicContentSize : CGSize {
169+ return mainFrameLayout. sizeThatFits ( CGSize ( width: frame. width, height: CGFloat . greatestFiniteMagnitude) )
170+ }
170171}
171-
0 commit comments