Skip to content

Commit b72982d

Browse files
author
Luc Dion
committed
Standardize layouts a little bit more.
1 parent 53643d2 commit b72982d

18 files changed

+118
-70
lines changed

LayoutFrameworkBenchmark.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
TargetAttributes = {
242242
24661CFB1F4EFFF5002CB883 = {
243243
CreatedOnToolsVersion = 8.3.2;
244-
DevelopmentTeam = 385YL4KG69;
244+
DevelopmentTeam = 4Q596JWQC5;
245245
LastSwiftMigration = 0920;
246246
ProvisioningStyle = Automatic;
247247
};
@@ -481,7 +481,7 @@
481481
buildSettings = {
482482
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
483483
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
484-
DEVELOPMENT_TEAM = 385YL4KG69;
484+
DEVELOPMENT_TEAM = 4Q596JWQC5;
485485
INFOPLIST_FILE = LayoutFrameworkBenchmark/Info.plist;
486486
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
487487
PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.LayoutFrameworkBenchmark;
@@ -498,7 +498,7 @@
498498
buildSettings = {
499499
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
500500
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
501-
DEVELOPMENT_TEAM = 385YL4KG69;
501+
DEVELOPMENT_TEAM = 4Q596JWQC5;
502502
INFOPLIST_FILE = LayoutFrameworkBenchmark/Info.plist;
503503
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
504504
PRODUCT_BUNDLE_IDENTIFIER = com.lucdion.LayoutFrameworkBenchmark;

LayoutFrameworkBenchmark/Benchmarks/AutoLayout/FeedItemAutoLayoutView.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,25 @@ class MiniProfileView: UIView {
135135
return i
136136
}()
137137

138-
let posterNameLabel: UILabel = UILabel()
138+
let posterNameLabel: UILabel = {
139+
let l = UILabel()
140+
l.backgroundColor = UIColor.yellow
141+
return l
142+
}()
139143

140144
let posterHeadlineLabel: UILabel = {
141145
let l = UILabel()
142146
l.numberOfLines = 3
147+
l.backgroundColor = UIColor.yellow
148+
return l
149+
}()
150+
151+
let posterTimeLabel: UILabel = {
152+
let l = UILabel()
153+
l.backgroundColor = UIColor.yellow
143154
return l
144155
}()
145156

146-
let posterTimeLabel: UILabel = UILabel()
147157
let posterCommentLabel: UILabel = UILabel()
148158

149159
init() {
@@ -176,14 +186,14 @@ class SocialActionsView: UIView {
176186
let likeLabel: UILabel = {
177187
let l = UILabel()
178188
l.text = "Like"
179-
l.backgroundColor = UIColor(red: 0, green: 0.9, blue: 0, alpha: 1)
189+
l.backgroundColor = .green
180190
return l
181191
}()
182192

183193
let commentLabel: UILabel = {
184194
let l = UILabel()
185195
l.text = "Comment"
186-
l.backgroundColor = UIColor(red: 0, green: 1.0, blue: 0, alpha: 1)
196+
l.backgroundColor = .green
187197
l.textAlignment = .center
188198
return l
189199
}()
@@ -192,7 +202,7 @@ class SocialActionsView: UIView {
192202
let l = UILabel()
193203
l.text = "Share"
194204
l.textAlignment = .right
195-
l.backgroundColor = UIColor(red: 0, green: 0.8, blue: 0, alpha: 1)
205+
l.backgroundColor = .green
196206
return l
197207
}()
198208

@@ -235,7 +245,6 @@ class TopBarView: UIView {
235245

236246
init() {
237247
super.init(frame: .zero)
238-
backgroundColor = UIColor.blue
239248
let views: [String: UIView] = ["actionLabel": actionLabel, "optionsLabel": optionsLabel]
240249
addAutoLayoutSubviews(views)
241250
addConstraints(withVisualFormat: "H:|-0-[actionLabel]-0-[optionsLabel]-0-|", views: views)

LayoutFrameworkBenchmark/Benchmarks/LayoutKit/FeedItemLayoutKitView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class FeedItemLayoutKitView: UIView, DataBinder {
2828
func setData(_ data: FeedItemData) {
2929
let posterProfile = ProfileCardLayout(
3030
name: data.posterName,
31-
connectionDegree: "2nd",
3231
headline: data.posterHeadline,
3332
timestamp: data.posterTimestamp,
3433
profileImageName: "50x50.png")

LayoutFrameworkBenchmark/Benchmarks/LayoutKit/Layouts/ProfileCardLayout.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import LayoutKit
1111

1212
open class ProfileCardLayout: StackLayout<UIView> {
1313

14-
public init(name: String, connectionDegree: String, headline: String, timestamp: String, profileImageName: String) {
14+
public init(name: String, headline: String, timestamp: String, profileImageName: String) {
1515
let labelConfig = { (label: UILabel) in
1616
label.backgroundColor = UIColor.yellow
1717
}
@@ -21,9 +21,6 @@ open class ProfileCardLayout: StackLayout<UIView> {
2121
spacing: 4,
2222
sublayouts: [
2323
LabelLayout(text: name, viewReuseId: "name", config: labelConfig),
24-
LabelLayout(text: connectionDegree, viewReuseId: "connectionDegree", config: { label in
25-
label.backgroundColor = UIColor.gray
26-
}),
2724
]
2825
)
2926

LayoutFrameworkBenchmark/Benchmarks/ManualLayout/FeedItemManualView.swift

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import UIKit
1010

1111
/// A LinkedIn feed item that is implemented with manual layout code.
1212
class 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 {

LayoutFrameworkBenchmark/Benchmarks/NKFrameLayoutKit/NKFrameLayoutKitView.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class NKFrameLayoutKitView: UIView, DataBinder {
1515

1616
let actionLabel: UILabel = {
1717
let l = UILabel()
18-
l.backgroundColor = UIColor.blue
1918
return l
2019
}()
2120

@@ -33,15 +32,24 @@ class NKFrameLayoutKitView: UIView, DataBinder {
3332
return i
3433
}()
3534

36-
let posterNameLabel: UILabel = UILabel()
35+
let posterNameLabel: UILabel = {
36+
let l = UILabel()
37+
l.backgroundColor = UIColor.yellow
38+
return l
39+
}()
3740

3841
let posterHeadlineLabel: UILabel = {
3942
let l = UILabel()
4043
l.numberOfLines = 3
4144
return l
4245
}()
4346

44-
let posterTimeLabel: UILabel = UILabel()
47+
let posterTimeLabel: UILabel = {
48+
let l = UILabel()
49+
l.backgroundColor = UIColor.yellow
50+
return l
51+
}()
52+
4553
let posterCommentLabel: UILabel = UILabel()
4654

4755
let contentImageView: UIImageView = {
@@ -56,23 +64,23 @@ class NKFrameLayoutKitView: UIView, DataBinder {
5664

5765
let likeLabel: UILabel = {
5866
let l = UILabel()
59-
l.backgroundColor = UIColor(red: 0, green: 0.9, blue: 0, alpha: 1)
67+
l.backgroundColor = .green
6068
l.text = "Like"
6169
return l
6270
}()
6371

6472
let commentLabel: UILabel = {
6573
let l = UILabel()
6674
l.text = "Comment"
67-
l.backgroundColor = UIColor(red: 0, green: 1.0, blue: 0, alpha: 1)
75+
l.backgroundColor = .green
6876
l.textAlignment = .center
6977
return l
7078
}()
7179

7280
let shareLabel: UILabel = {
7381
let l = UILabel()
7482
l.text = "Share"
75-
l.backgroundColor = UIColor(red: 0, green: 0.8, blue: 0, alpha: 1)
83+
l.backgroundColor = .green
7684
l.textAlignment = .right
7785
return l
7886
}()

0 commit comments

Comments
 (0)