Skip to content

Commit abdbc95

Browse files
authored
Merge pull request #145 from layoutBox/add_wrapContent_example
Add a wrapContent example
2 parents 6c611e4 + e2917b5 commit abdbc95

File tree

13 files changed

+366
-60
lines changed

13 files changed

+366
-60
lines changed

Example/PinLayoutSample.xcodeproj/project.pbxproj

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
DF4C1AAA205AF10900DED50B /* RoundedButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF4C1AA7205AF10900DED50B /* RoundedButton.swift */; };
5050
DF4C1AAE205AF78A00DED50B /* SafeAreaCornersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF4C1AAC205AF78A00DED50B /* SafeAreaCornersViewController.swift */; };
5151
DF4C1AAF205AF78A00DED50B /* SafeAreaCornersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF4C1AAD205AF78A00DED50B /* SafeAreaCornersView.swift */; };
52+
DFEAF74A20C9648A00E33147 /* WrapContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFEAF74920C9648A00E33147 /* WrapContentView.swift */; };
53+
DFEAF74C20C9649F00E33147 /* WrapContentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFEAF74B20C9649F00E33147 /* WrapContentViewController.swift */; };
5254
/* End PBXBuildFile section */
5355

5456
/* Begin PBXContainerItemProxy section */
@@ -80,6 +82,27 @@
8082
remoteGlobalIDString = 244DF2F81EF46C500090508B;
8183
remoteInfo = PinLayoutTVOS;
8284
};
85+
DFEAF71B20C840F300E33147 /* PBXContainerItemProxy */ = {
86+
isa = PBXContainerItemProxy;
87+
containerPortal = 2439CC1E1E665858003326FB /* PinLayout.xcodeproj */;
88+
proxyType = 2;
89+
remoteGlobalIDString = DF1A5D2C2084CF9700725EF5;
90+
remoteInfo = "PinLayout-macOS";
91+
};
92+
DFEAF71D20C840F300E33147 /* PBXContainerItemProxy */ = {
93+
isa = PBXContainerItemProxy;
94+
containerPortal = 2439CC1E1E665858003326FB /* PinLayout.xcodeproj */;
95+
proxyType = 2;
96+
remoteGlobalIDString = DF1A5D1D2084C94700725EF5;
97+
remoteInfo = "PinLayoutTests-macOS";
98+
};
99+
DFEAF71F20C840F300E33147 /* PBXContainerItemProxy */ = {
100+
isa = PBXContainerItemProxy;
101+
containerPortal = 2439CC1E1E665858003326FB /* PinLayout.xcodeproj */;
102+
proxyType = 2;
103+
remoteGlobalIDString = DFF6F9C22084DCD3004F5AED;
104+
remoteInfo = "PinLayoutTests-tvOS";
105+
};
83106
/* End PBXContainerItemProxy section */
84107

85108
/* Begin PBXCopyFilesBuildPhase section */
@@ -156,6 +179,8 @@
156179
DF4C1AA7205AF10900DED50B /* RoundedButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoundedButton.swift; sourceTree = "<group>"; };
157180
DF4C1AAC205AF78A00DED50B /* SafeAreaCornersViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SafeAreaCornersViewController.swift; sourceTree = "<group>"; };
158181
DF4C1AAD205AF78A00DED50B /* SafeAreaCornersView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SafeAreaCornersView.swift; sourceTree = "<group>"; };
182+
DFEAF74920C9648A00E33147 /* WrapContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WrapContentView.swift; sourceTree = "<group>"; };
183+
DFEAF74B20C9649F00E33147 /* WrapContentViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WrapContentViewController.swift; sourceTree = "<group>"; };
159184
/* End PBXFileReference section */
160185

161186
/* Begin PBXFrameworksBuildPhase section */
@@ -195,8 +220,11 @@
195220
isa = PBXGroup;
196221
children = (
197222
2439CC241E665858003326FB /* PinLayout.framework */,
198-
24DA374F1EF7F90700D1AB2F /* PinLayoutTVOS.framework */,
199-
2439CC261E665858003326FB /* PinLayoutTests.xctest */,
223+
DFEAF71C20C840F300E33147 /* PinLayout.framework */,
224+
24DA374F1EF7F90700D1AB2F /* PinLayout.framework */,
225+
2439CC261E665858003326FB /* PinLayoutTests-iOS.xctest */,
226+
DFEAF71E20C840F300E33147 /* PinLayoutTests-macOS.xctest */,
227+
DFEAF72020C840F300E33147 /* PinLayoutTests-tvOS.xctest */,
200228
);
201229
name = Products;
202230
sourceTree = "<group>";
@@ -220,6 +248,7 @@
220248
24A9C1EF1EF0542500F2CF64 /* TableViewExample */,
221249
24F2460C1FA8D4D100B6332E /* CollectionViewExample */,
222250
DF4C1A9F205AEDFC00DED50B /* SafeArea */,
251+
DFEAF71520C840F300E33147 /* WrapContent */,
223252
2497CFEA1EF40B8100DFD13B /* Form */,
224253
24D18D181F3DECD6008129EF /* IntroRTL */,
225254
2416376F1F8E4BC200EE703A /* IntroObjectiveC */,
@@ -411,6 +440,15 @@
411440
path = AutoAdjustingSize;
412441
sourceTree = "<group>";
413442
};
443+
DFEAF71520C840F300E33147 /* WrapContent */ = {
444+
isa = PBXGroup;
445+
children = (
446+
DFEAF74920C9648A00E33147 /* WrapContentView.swift */,
447+
DFEAF74B20C9649F00E33147 /* WrapContentViewController.swift */,
448+
);
449+
path = WrapContent;
450+
sourceTree = "<group>";
451+
};
414452
F143180314A617EFD07C5709 /* Pods */ = {
415453
isa = PBXGroup;
416454
children = (
@@ -494,20 +532,41 @@
494532
remoteRef = 2439CC231E665858003326FB /* PBXContainerItemProxy */;
495533
sourceTree = BUILT_PRODUCTS_DIR;
496534
};
497-
2439CC261E665858003326FB /* PinLayoutTests.xctest */ = {
535+
2439CC261E665858003326FB /* PinLayoutTests-iOS.xctest */ = {
498536
isa = PBXReferenceProxy;
499537
fileType = wrapper.cfbundle;
500-
path = PinLayoutTests.xctest;
538+
path = "PinLayoutTests-iOS.xctest";
501539
remoteRef = 2439CC251E665858003326FB /* PBXContainerItemProxy */;
502540
sourceTree = BUILT_PRODUCTS_DIR;
503541
};
504-
24DA374F1EF7F90700D1AB2F /* PinLayoutTVOS.framework */ = {
542+
24DA374F1EF7F90700D1AB2F /* PinLayout.framework */ = {
505543
isa = PBXReferenceProxy;
506544
fileType = wrapper.framework;
507-
path = PinLayoutTVOS.framework;
545+
path = PinLayout.framework;
508546
remoteRef = 24DA374E1EF7F90700D1AB2F /* PBXContainerItemProxy */;
509547
sourceTree = BUILT_PRODUCTS_DIR;
510548
};
549+
DFEAF71C20C840F300E33147 /* PinLayout.framework */ = {
550+
isa = PBXReferenceProxy;
551+
fileType = wrapper.framework;
552+
path = PinLayout.framework;
553+
remoteRef = DFEAF71B20C840F300E33147 /* PBXContainerItemProxy */;
554+
sourceTree = BUILT_PRODUCTS_DIR;
555+
};
556+
DFEAF71E20C840F300E33147 /* PinLayoutTests-macOS.xctest */ = {
557+
isa = PBXReferenceProxy;
558+
fileType = wrapper.cfbundle;
559+
path = "PinLayoutTests-macOS.xctest";
560+
remoteRef = DFEAF71D20C840F300E33147 /* PBXContainerItemProxy */;
561+
sourceTree = BUILT_PRODUCTS_DIR;
562+
};
563+
DFEAF72020C840F300E33147 /* PinLayoutTests-tvOS.xctest */ = {
564+
isa = PBXReferenceProxy;
565+
fileType = wrapper.cfbundle;
566+
path = "PinLayoutTests-tvOS.xctest";
567+
remoteRef = DFEAF71F20C840F300E33147 /* PBXContainerItemProxy */;
568+
sourceTree = BUILT_PRODUCTS_DIR;
569+
};
511570
/* End PBXReferenceProxy section */
512571

513572
/* Begin PBXResourcesBuildPhase section */
@@ -591,6 +650,7 @@
591650
2439CC551E665C6B003326FB /* RelativeViewController.swift in Sources */,
592651
247157941F87BD680003424F /* UIEdgeInsets+PinLayout.swift in Sources */,
593652
24D18D1E1F3DED0D008129EF /* IntroRTLViewController.swift in Sources */,
653+
DFEAF74C20C9649F00E33147 /* WrapContentViewController.swift in Sources */,
594654
24F246121FA8D4D100B6332E /* HouseCell.swift in Sources */,
595655
DF4C1AAE205AF78A00DED50B /* SafeAreaCornersViewController.swift in Sources */,
596656
24A9C2031EF16A3E00F2CF64 /* AutoAdjustingSizeView.swift in Sources */,
@@ -604,6 +664,7 @@
604664
2497CFED1EF40B9100DFD13B /* FormView.swift in Sources */,
605665
24F75B5B1EE5644E008DB567 /* IntroView.swift in Sources */,
606666
DF4C1AA5205AEDFC00DED50B /* SafeAreaViewController.swift in Sources */,
667+
DFEAF74A20C9648A00E33147 /* WrapContentView.swift in Sources */,
607668
249EFE431E64FAFE00165E39 /* AppDelegate.swift in Sources */,
608669
2497CFEE1EF40B9100DFD13B /* FormViewController.swift in Sources */,
609670
24A9C1F31EF0542F00F2CF64 /* TableViewExampleViewController.swift in Sources */,

Example/PinLayoutSample/UI/Common/Stylesheet.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ import UIKit
2121

2222
extension UIColor {
2323
class var pinLayoutColor: UIColor { return UIColor(red: 90.0 / 255.0, green: 171.0 / 255.0, blue: 243.0 / 255.0, alpha: 1.0) }
24+
class var lightColor: UIColor { return UIColor(red: 230.0 / 255.0, green: 240.0 / 255.0, blue: 255.0 / 255.0, alpha: 1.0) }
2425
}

Example/PinLayoutSample/UI/Examples/New Group/ObjectiveC.m

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Copyright (c) 2017 Luc Dion
2+
// Permission is hereby granted, free of charge, to any person obtaining a copy
3+
// of this software and associated documentation files (the "Software"), to deal
4+
// in the Software without restriction, including without limitation the rights
5+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6+
// copies of the Software, and to permit persons to whom the Software is
7+
// furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in
10+
// all copies or substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18+
// THE SOFTWARE.
19+
20+
import UIKit
21+
import PinLayout
22+
23+
class WrapContentView: UIView {
24+
fileprivate let topContainer = UIView()
25+
fileprivate let topLogo = UIImageView(image: UIImage(named: "PinLayout-logo"))
26+
fileprivate let topLabel = UILabel()
27+
28+
fileprivate let separatorView1 = UIView()
29+
30+
fileprivate let middleContainer = UIView()
31+
fileprivate let middleLabel = UILabel()
32+
fileprivate let button1 = UIButton(type: .custom)
33+
fileprivate let button2 = UIButton(type: .custom)
34+
fileprivate let button3 = UIButton(type: .custom)
35+
36+
fileprivate let separatorView2 = UIView()
37+
38+
fileprivate let bottomContainer = UIView()
39+
fileprivate let bottomLogo = UIImageView(image: UIImage(named: "PinLayout-logo"))
40+
fileprivate let bottomLabel = UILabel()
41+
42+
init() {
43+
super.init(frame: .zero)
44+
backgroundColor = .white
45+
46+
topContainer.backgroundColor = .lightColor
47+
addSubview(topContainer)
48+
49+
//
50+
// Top section
51+
//
52+
topLogo.contentMode = .scaleAspectFit
53+
topContainer.addSubview(topLogo)
54+
55+
configureLabel(topLabel, text: "This view use 'pin.wrapContent()' to wrap its subviews (logo and label). This view horizontally center at the top.")
56+
topContainer.addSubview(topLabel)
57+
58+
// Separator 1
59+
separatorView1.pin.height(1)
60+
separatorView1.backgroundColor = .pinLayoutColor
61+
addSubview(separatorView1)
62+
63+
//
64+
// Middle section
65+
//
66+
middleContainer.backgroundColor = .lightColor
67+
addSubview(middleContainer)
68+
69+
configureLabel(middleLabel, text: "This view use 'pin.wrapContent()' to wrap its subviews (1 label and 3 buttons). This view is horizontally centered.")
70+
middleContainer.addSubview(middleLabel)
71+
72+
button1.setTitle("Button 1", for: .normal)
73+
button1.setTitleColor(.black, for: .normal)
74+
button1.sizeToFit()
75+
middleContainer.addSubview(button1)
76+
77+
button2.setTitle("Button 2", for: .normal)
78+
button2.setTitleColor(.black, for: .normal)
79+
button2.sizeToFit()
80+
middleContainer.addSubview(button2)
81+
82+
button3.setTitle("Button 3", for: .normal)
83+
button3.setTitleColor(.black, for: .normal)
84+
button3.sizeToFit()
85+
middleContainer.addSubview(button3)
86+
87+
// Separator 2
88+
separatorView2.pin.height(1)
89+
separatorView2.backgroundColor = .pinLayoutColor
90+
addSubview(separatorView2)
91+
92+
//
93+
// Bottom section
94+
//
95+
bottomContainer.backgroundColor = .lightColor
96+
addSubview(bottomContainer)
97+
98+
bottomLogo.contentMode = .scaleAspectFit
99+
bottomContainer.addSubview(bottomLogo)
100+
101+
configureLabel(bottomLabel, text: "This view use 'pin.wrapContent()' to wrap its subviews (logo and label). This view is horizontally centered. This view is vertically center in the region between the separator and the bottom of the screen using '.align(.center)'")
102+
bottomContainer.addSubview(bottomLabel)
103+
}
104+
105+
required init?(coder aDecoder: NSCoder) {
106+
super.init(coder: aDecoder)
107+
}
108+
109+
override func layoutSubviews() {
110+
super.layoutSubviews()
111+
let padding: CGFloat = 10
112+
113+
// Top section
114+
topLogo.pin.width(100).aspectRatio()
115+
topLabel.pin.below(of: topLogo, aligned: .center).width(260).sizeToFit(.width).marginTop(padding)
116+
topContainer.pin.wrapContent(padding: 4).top(pin.safeArea.top + padding).hCenter()
117+
118+
// Separator1
119+
separatorView1.pin.below(of: topContainer, aligned: .center).width(80%).marginTop(padding)
120+
121+
middleLabel.pin.width(260).sizeToFit(.width)
122+
button2.pin.below(of: middleLabel, aligned: .center).marginTop(padding)
123+
button1.pin.before(of: button2, aligned: .center).marginRight(padding)
124+
button3.pin.after(of: button2, aligned: .center).marginLeft(padding)
125+
middleContainer.pin.wrapContent(padding: 4).below(of: separatorView1).hCenter().marginTop(padding)
126+
127+
// Separator2
128+
separatorView2.pin.below(of: middleContainer, aligned: .center).width(80%).marginTop(padding)
129+
130+
// Bottom section
131+
bottomLogo.pin.width(100).aspectRatio()
132+
bottomLabel.pin.after(of: bottomLogo, aligned: .top).width(200).sizeToFit(.width)
133+
bottomContainer.pin.wrapContent(padding: 4).below(of: separatorView2).bottom().align(.center).hCenter()
134+
}
135+
136+
private func configureLabel(_ label: UILabel, text: String) {
137+
label.text = text
138+
label.font = .systemFont(ofSize: 14)
139+
label.textAlignment = .center
140+
label.numberOfLines = 0
141+
label.lineBreakMode = .byWordWrapping
142+
}
143+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2017 Luc Dion
2+
// Permission is hereby granted, free of charge, to any person obtaining a copy
3+
// of this software and associated documentation files (the "Software"), to deal
4+
// in the Software without restriction, including without limitation the rights
5+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6+
// copies of the Software, and to permit persons to whom the Software is
7+
// furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in
10+
// all copies or substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18+
// THE SOFTWARE.
19+
20+
import UIKit
21+
22+
class WrapContentViewController: UIViewController {
23+
fileprivate var mainView: WrapContentView {
24+
return self.view as! WrapContentView
25+
}
26+
27+
init(pageType: PageType) {
28+
super.init(nibName: nil, bundle: nil)
29+
30+
title = pageType.text
31+
}
32+
33+
required init?(coder aDecoder: NSCoder) {
34+
super.init(coder: aDecoder)
35+
}
36+
37+
override func loadView() {
38+
view = WrapContentView()
39+
}
40+
}

Example/PinLayoutSample/UI/Menu/MenuViewController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum PageType: Int {
2525
case tableView
2626
case collectionView
2727
case safeArea
28+
case wrapContent
2829
case form
2930
case relativePositions
3031
case multiRelativePositions
@@ -41,6 +42,7 @@ enum PageType: Int {
4142
case .tableView: return "UITableView with variable cell's height"
4243
case .collectionView: return "UICollectionView Example"
4344
case .safeArea: return "SafeArea"
45+
case .wrapContent: return "wrapContent Example"
4446
case .form: return "Form Example"
4547
case .relativePositions: return "Relative Positionning"
4648
case .multiRelativePositions: return "Multiple Relatives Positionning"
@@ -65,6 +67,8 @@ enum PageType: Int {
6567
let tabbarController = UITabBarController()
6668
tabbarController.setViewControllers([SafeAreaViewController(), SafeAreaCornersViewController()], animated: false)
6769
return tabbarController
70+
case .wrapContent:
71+
return WrapContentViewController(pageType: self)
6872
case .form:
6973
return FormViewController(pageType: self)
7074
case .relativePositions:

0 commit comments

Comments
 (0)