Skip to content

Commit 3437838

Browse files
committed
Revert "Adjust to Container Size" sample code
1 parent faeb598 commit 3437838

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Example/PinLayoutSample/UI/Examples/AdjustToContainer/Subviews/ChoiceSelectorView.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,21 @@ class ChoiceSelectorView: UIView {
4646

4747
override func layoutSubviews() {
4848
super.layoutSubviews()
49-
layout()
49+
_ = layout()
5050
}
5151

52-
private func layout() {
52+
override func sizeThatFits(_ size: CGSize) -> CGSize {
53+
// 1) Set the width to the specified width
54+
self.pin.width(size.width)
55+
56+
// 2) Layout the contentView's controls
57+
return layout()
58+
}
59+
60+
private func layout() -> CGSize {
5361
let margin: CGFloat = 12
5462

55-
if bounds.width > 500 {
63+
if frame.width > 500 {
5664
// The UISegmentedControl is at the top-right corner and the label takes the remaining horizontal space.
5765
segmentedControl.pin.top().right().margin(margin)
5866
textLabel.pin.top().left().before(of: segmentedControl).margin(margin).sizeToFit(.width)
@@ -61,9 +69,7 @@ class ChoiceSelectorView: UIView {
6169
textLabel.pin.top().horizontally().margin(margin).sizeToFit(.width)
6270
segmentedControl.pin.below(of: textLabel).right().margin(margin)
6371
}
64-
}
6572

66-
override func sizeThatFits(_ size: CGSize) -> CGSize {
67-
return autoSizeThatFits(size) { layout() }
73+
return CGSize(width: frame.width, height: max(textLabel.frame.maxY, segmentedControl.frame.maxY) + margin)
6874
}
6975
}

0 commit comments

Comments
 (0)