Skip to content

Commit b4105d3

Browse files
authored
Merge pull request #101 from mirego/add_fitWidth_fitHeight
New method `sizeToFit(:FitType)` & `fitSize()` is now deprecated
2 parents 4987499 + 2577938 commit b4105d3

28 files changed

+635
-276
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ build/
66
xcuserdata
77
data/
88

9-
Pods/
9+
Pods/
10+
11+
docs/1.2

Example/PinLayoutSample/UI/Common/BasicView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,19 @@ 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
50+
var sizeThatFitSizeOffset: CGFloat = 0
5051

5152
override func sizeThatFits(_ size: CGSize) -> CGSize {
5253
var newSize = CGSize()
5354
if size.width != CGFloat.greatestFiniteMagnitude {
54-
newSize.width = size.width
55+
newSize.width = size.width + sizeThatFitSizeOffset
5556
newSize.height = sizeThatFitsExpectedArea / newSize.width
5657
} else if size.height != CGFloat.greatestFiniteMagnitude {
57-
newSize.height = size.height
58+
newSize.height = size.height + sizeThatFitSizeOffset
5859
newSize.width = sizeThatFitsExpectedArea / newSize.height
5960
} else {
6061
newSize.width = 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().fitSize()
50-
swiftOpinionSelectorView.pin.below(of: languageSelectorView, aligned: .left).right().marginTop(10).fitSize()
51-
swiftUsageSelectorView.pin.below(of: swiftOpinionSelectorView, aligned: .left).right().marginTop(10).fitSize()
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class HouseCell: UICollectionViewCell {
6565
nameLabel.text = house.name
6666
priceLabel.text = house.price
6767
distanceLabel.text = "\(house.distance) KM"
68+
distanceLabel.textAlignment = .right
6869

6970
mainImage.download(url: house.mainImageURL)
7071
mainImage.contentMode = .scaleAspectFill
@@ -79,13 +80,13 @@ class HouseCell: UICollectionViewCell {
7980

8081
private func layout() {
8182
headerView.pin.top().horizontally().height(100)
82-
nameLabel.pin.top().horizontally().margin(padding).fitSize()
83+
nameLabel.pin.top().horizontally().margin(padding).sizeToFit(.width)
8384

8485
mainImage.pin.below(of: nameLabel).horizontally().height(300).marginTop(padding)
8586

8687
footerView.pin.below(of: mainImage).horizontally()
87-
priceLabel.pin.top().horizontally().fitSize().margin(6, padding)
88-
distanceLabel.pin.top().after(of: priceLabel).right().fitSize().justify(.right).margin(6, padding)
88+
priceLabel.pin.top().horizontally().margin(6, padding).sizeToFit(.width)
89+
distanceLabel.pin.top().after(of: priceLabel).right().margin(6, padding).sizeToFit(.width)
8990
footerView.pin.height(max(priceLabel.frame.maxY, distanceLabel.frame.maxY) + 6)
9091

9192
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).fitSize()
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] fitSize] 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).fitSize()
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).fitSize()
65-
descriptionLabel.pin.below(of: [iconImageView, nameLabel]).left().right().margin(margin).fitSize()
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).fitSize()
46+
titleLabel.pin.left().right().vCenter().margin(10).sizeToFit(.width)
4747
}
4848
}

0 commit comments

Comments
 (0)