Skip to content

Commit d1c95f2

Browse files
author
Luc Dion
committed
New method sizeToFit(:FitType) & fitSize() is now deprecated
* `fitSize()` is now deprecated. The new `sizeToFit(:FitType)` should be used instead. **`sizeToFit(_ fitType: FitType)`** The method adjust the view's size based on the view's `sizeThatFits()` method result. PinLayout will adjust either the view's width or height based on the `fitType` parameter value. Notes: * If margin rules apply, margins will be applied when determining the reference dimension (width/height). * The resulting size will always respect `minWidth` / `maxWidth` / `minHeight` / `maxHeight`. - Parameter fitType: Identify the reference dimension (width / height) that will be used to adjust the view's size: .width: The method adjust the view's size based on the **reference width**. * If properties related to the width have been pinned (e.g: width, left & right, margins, ...), the **reference width will be determined by these properties**, else the **current view's width** will be used. * The resulting width will always **match the reference width**. .height: The method adjust the view's size based on the **reference height**. * If properties related to the height have been pinned (e.g: height, top & bottom, margins, ...), the **reference height will be determined by these properties**, else the **current view's height** will be used. * The resulting height will always **match the reference height**. .widthFlexible: Similar to `.width`, except that PinLayout won't constrain the resulting width to match the reference width. The resulting width may be smaller of bigger depending on the view's sizeThatFits(..) method result. For example a single line UILabel may returns a smaller width if its string is smaller than the reference width. .heightFlexible: Similar to `.height`, except that PinLayout won't constrain the resulting height to match the reference height. The resulting height may be smaller of bigger depending on the view's sizeThatFits(..) method result. Examples: ``` // Adjust the view's size based on a width of 100 pixels. // The resulting width will always match the pinned property `width(100)`. view.pin.width(100).sizeToFit(.width) // Adjust the view's size based on view's current width. // The resulting width will always match the view's original width. // The resulting height will never be bigger than the specified `maxHeight`. view.pin.sizeToFit(.width).maxHeight(100) // Adjust the view's size based on 100% of the superview's height. // The resulting height will always match the pinned property `height(100%)`. view.pin.height(100%).sizeToFit(.height) // Adjust the view's size based on view's current height. // The resulting width will always match the view's original height. view.pin.sizeToFit(.height) // Since `.widthFlexible` has been specified, its possible that the resulting // width will be smaller or bigger than 100 pixels, based of the label's sizeThatFits() // method result. label.pin.width(100).sizeToFit(.widthFlexible) ```
1 parent f093942 commit d1c95f2

File tree

19 files changed

+329
-354
lines changed

19 files changed

+329
-354
lines changed

Example/PinLayoutSample/UI/Common/BasicView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class BasicView: UIView {
4343
override func layoutSubviews() {
4444
super.layoutSubviews()
4545

46-
label.pin.top().left().right().margin(4).fitSize()
46+
label.pin.top().left().right().margin(4).sizeToFit(.width)
4747
}
4848

4949
var sizeThatFitsExpectedArea: CGFloat = 40 * 40

Example/PinLayoutSample/UI/Examples/AdjustToContainer/AdjustToContainerView.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ import PinLayout
2323
class AdjustToContainerView: BaseView {
2424
fileprivate let contentView = UIView()
2525
fileprivate let languageSelectorView = ChoiceSelectorView(text: "What is your favorite language?", choices: ["Swift", "Objective-C", "C++"])
26-
fileprivate let swiftOpinionSelectorView = ChoiceSelectorView(text: "Overall, are you satisfied with the Swift performance in your projects?", choices: ["Yes", "No"])
27-
fileprivate let swiftUsageSelectorView = ChoiceSelectorView(text: "How often do you typically use Swift?", choices: ["Daily", "Weekly", "Montly", "Do not use"])
26+
fileprivate let swiftOpinionSelector = ChoiceSelectorView(text: "Overall, are you satisfied with the Swift performance in your projects?", choices: ["Yes", "No"])
27+
fileprivate let swiftUsageSelector = ChoiceSelectorView(text: "How often do you typically use Swift?", choices: ["Daily", "Weekly", "Montly", "Do not use"])
2828

2929
override init() {
3030
super.init()
3131

3232
addSubview(contentView)
3333

3434
contentView.addSubview(languageSelectorView)
35-
contentView.addSubview(swiftOpinionSelectorView)
36-
contentView.addSubview(swiftUsageSelectorView)
35+
contentView.addSubview(swiftOpinionSelector)
36+
contentView.addSubview(swiftUsageSelector)
3737
}
3838

3939
required init?(coder aDecoder: NSCoder) {
@@ -46,8 +46,8 @@ class AdjustToContainerView: BaseView {
4646
// Layout the contentView using the view's safeArea.
4747
contentView.pin.all().margin(safeArea)
4848

49-
languageSelectorView.pin.top().left().right().fitWidth()
50-
swiftOpinionSelectorView.pin.below(of: languageSelectorView, aligned: .left).right().marginTop(10).fitWidth()
51-
swiftUsageSelectorView.pin.below(of: swiftOpinionSelectorView, aligned: .left).right().marginTop(10).fitWidth()
49+
languageSelectorView.pin.top().left().right().sizeToFit(.width)
50+
swiftOpinionSelector.pin.below(of: languageSelectorView, aligned: .left).right().marginTop(10).sizeToFit(.width)
51+
swiftUsageSelector.pin.below(of: swiftOpinionSelector, aligned: .left).right().marginTop(10).sizeToFit(.width)
5252
}
5353
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ class ChoiceSelectorView: UIView {
6363
if frame.width > 500 {
6464
// The UISegmentedControl is at the top-right corner and the label takes the remaining horizontal space.
6565
segmentedControl.pin.top().right().margin(margin)
66-
textLabel.pin.top().left().before(of: segmentedControl).margin(margin).fitSize()
66+
textLabel.pin.top().left().before(of: segmentedControl).margin(margin).sizeToFit(.width)
6767
} else {
6868
// The UISegmentedControl is placed below the label.
69-
textLabel.pin.top().left().right().margin(margin).fitSize()
69+
textLabel.pin.top().left().right().margin(margin).sizeToFit(.width)
7070
segmentedControl.pin.below(of: textLabel).right().margin(margin)
7171
}
7272

Example/PinLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ class HouseCell: UICollectionViewCell {
8080

8181
private func layout() {
8282
headerView.pin.top().horizontally().height(100)
83-
nameLabel.pin.top().horizontally().margin(padding).fitWidth()
83+
nameLabel.pin.top().horizontally().margin(padding).sizeToFit(.width)
8484

8585
mainImage.pin.below(of: nameLabel).horizontally().height(300).marginTop(padding)
8686

8787
footerView.pin.below(of: mainImage).horizontally()
88-
priceLabel.pin.top().horizontally().margin(6, padding).fitWidth()
89-
distanceLabel.pin.top().after(of: priceLabel).right().margin(6, padding).fitWidthHard()
88+
priceLabel.pin.top().horizontally().margin(6, padding).sizeToFit(.width)
89+
distanceLabel.pin.top().after(of: priceLabel).right().margin(6, padding).sizeToFit(.width)
9090
footerView.pin.height(max(priceLabel.frame.maxY, distanceLabel.frame.maxY) + 6)
9191

9292
contentView.pin.height(footerView.frame.maxY)

Example/PinLayoutSample/UI/Examples/Intro/IntroView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class IntroView: BaseView {
6464

6565
logo.pin.top().left().size(100).aspectRatio().marginTop(10)
6666
segmented.pin.after(of: logo, aligned: .top).right().marginLeft(10)
67-
textLabel.pin.below(of: segmented, aligned: .left).width(of: segmented).pinEdges().marginTop(10).fitWidth()
67+
textLabel.pin.below(of: segmented, aligned: .left).width(of: segmented).pinEdges().marginTop(10).sizeToFit(.width)
6868
separatorView.pin.below(of: [logo, textLabel], aligned: .left).right(to: segmented.edge.right).marginTop(10)
6969
}
7070
}

Example/PinLayoutSample/UI/Examples/IntroObjectiveC/IntroObjectiveCView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ - (void) layoutSubviews {
6161

6262
[[[[[[logo.pinObjc top] left] width:100] aspectRatio] marginWithTop:topLayoutGuide + 10 horizontal:10 bottom:10] layout];
6363
[[[[segmented.pinObjc rightOf:logo aligned:VerticalAlignTop] right] marginHorizontal:10] layout];
64-
[[[[[[textLabel.pinObjc belowOf:segmented aligned:HorizontalAlignLeft] widthOf:segmented] pinEdges] marginTop:10] fitWidth] layout];
64+
[[[[[[textLabel.pinObjc belowOf:segmented aligned:HorizontalAlignLeft] widthOf:segmented] pinEdges] marginTop:10] sizeToFit:FitWidth] layout];
6565
[[[[[separatorView.pinObjc belowOfViews:@[logo, textLabel] aligned:HorizontalAlignLeft] rightTo:segmented.edge.right] height:1] marginTop:10] layout];
6666
}
6767

Example/PinLayoutSample/UI/Examples/IntroRTL/IntroRTLView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class IntroRTLView: BaseView {
6969

7070
logo.pin.top().start().size(100).aspectRatio().marginTop(10)
7171
segmented.pin.after(of: logo, aligned: .top).end().marginStart(10)
72-
textLabel.pin.below(of: segmented, aligned: .start).width(of: segmented).pinEdges().marginTop(10).fitWidth()
72+
textLabel.pin.below(of: segmented, aligned: .start).width(of: segmented).pinEdges().marginTop(10).sizeToFit(.width)
7373
separatorView.pin.below(of: [logo, textLabel], aligned: .start).end(to: segmented.edge.end).marginTop(10)
7474
}
7575
}

Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodCell.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class MethodCell: UITableViewCell {
6161

6262
fileprivate func layout() {
6363
iconImageView.pin.top().left().size(30).margin(margin)
64-
nameLabel.pin.right(of: iconImageView, aligned: .center).right().marginHorizontal(margin).fitWidth()
65-
descriptionLabel.pin.below(of: [iconImageView, nameLabel]).left().right().margin(margin).fitWidth()
64+
nameLabel.pin.right(of: iconImageView, aligned: .center).right().marginHorizontal(margin).sizeToFit(.width)
65+
descriptionLabel.pin.below(of: [iconImageView, nameLabel]).left().right().margin(margin).sizeToFit(.width)
6666
}
6767

6868
override func sizeThatFits(_ size: CGSize) -> CGSize {

Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodGroupHeader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ class MethodGroupHeader: UITableViewHeaderFooterView {
4343
override func layoutSubviews() {
4444
super.layoutSubviews()
4545

46-
titleLabel.pin.left().right().vCenter().margin(10).fitWidth()
46+
titleLabel.pin.left().right().vCenter().margin(10).sizeToFit(.width)
4747
}
4848
}

PinLayout.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = "PinLayout"
11-
s.version = "1.4.2"
11+
s.version = "1.5.0"
1212
s.summary = "Fast Swift UIViews layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable."
1313
s.description = "Fast Swift UIViews layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable."
1414

0 commit comments

Comments
 (0)