Skip to content
This repository was archived by the owner on Sep 15, 2019. It is now read-only.

Commit 6baf14c

Browse files
authored
Merge pull request #12 from sp71/feature/updateExample
[FEATURE] Update Example Project
2 parents 9852702 + 8a177d2 commit 6baf14c

13 files changed

+450
-44
lines changed

Example/SnapLayout.xcodeproj/project.pbxproj

+72-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
053493EC1EBD486B00D9F89D /* SizeTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 053493EB1EBD486B00D9F89D /* SizeTableViewCell.swift */; };
11+
053493F11EBD4E7300D9F89D /* AdjacentVerticalTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 053493F01EBD4E7300D9F89D /* AdjacentVerticalTableViewCell.swift */; };
1012
0543392C1EA1FB1100044728 /* BaseTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0543392B1EA1FB1100044728 /* BaseTestCase.swift */; };
13+
057099511EBD7B7F00D6EF71 /* AdjacentHorizontalTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 057099501EBD7B7F00D6EF71 /* AdjacentHorizontalTableViewCell.swift */; };
14+
057099531EBD7D3000D6EF71 /* Style.swift in Sources */ = {isa = PBXBuildFile; fileRef = 057099521EBD7D3000D6EF71 /* Style.swift */; };
15+
05B6D15C1EBC3B3400715D40 /* WelcomeTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B6D15B1EBC3B3400715D40 /* WelcomeTableViewCell.swift */; };
16+
05B6D15E1EBC3E6F00715D40 /* IndexManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B6D15D1EBC3E6F00715D40 /* IndexManager.swift */; };
17+
05B6D1601EBC434500715D40 /* PriorityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B6D15F1EBC434500715D40 /* PriorityTableViewCell.swift */; };
18+
05B6D1621EBC438300715D40 /* UITableViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B6D1611EBC438300715D40 /* UITableViewExtension.swift */; };
19+
05B6D1641EBC48CA00715D40 /* TitleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05B6D1631EBC48CA00715D40 /* TitleTableViewCell.swift */; };
1120
05D8B3621E8E1F7F00E5819A /* SnapConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D8B3611E8E1F7F00E5819A /* SnapConfigTests.swift */; };
1221
05D8B3641E8E1FAE00E5819A /* SnapManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D8B3631E8E1FAE00E5819A /* SnapManagerTests.swift */; };
1322
05FA916D1E919EE90033BC64 /* SnapLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05FA916C1E919EE90033BC64 /* SnapLayoutTests.swift */; };
@@ -30,7 +39,16 @@
3039
/* End PBXContainerItemProxy section */
3140

3241
/* Begin PBXFileReference section */
42+
053493EB1EBD486B00D9F89D /* SizeTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SizeTableViewCell.swift; sourceTree = "<group>"; };
43+
053493F01EBD4E7300D9F89D /* AdjacentVerticalTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdjacentVerticalTableViewCell.swift; sourceTree = "<group>"; };
3344
0543392B1EA1FB1100044728 /* BaseTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseTestCase.swift; sourceTree = "<group>"; };
45+
057099501EBD7B7F00D6EF71 /* AdjacentHorizontalTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdjacentHorizontalTableViewCell.swift; sourceTree = "<group>"; };
46+
057099521EBD7D3000D6EF71 /* Style.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Style.swift; sourceTree = "<group>"; };
47+
05B6D15B1EBC3B3400715D40 /* WelcomeTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WelcomeTableViewCell.swift; sourceTree = "<group>"; };
48+
05B6D15D1EBC3E6F00715D40 /* IndexManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndexManager.swift; sourceTree = "<group>"; };
49+
05B6D15F1EBC434500715D40 /* PriorityTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PriorityTableViewCell.swift; sourceTree = "<group>"; };
50+
05B6D1611EBC438300715D40 /* UITableViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableViewExtension.swift; sourceTree = "<group>"; };
51+
05B6D1631EBC48CA00715D40 /* TitleTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TitleTableViewCell.swift; sourceTree = "<group>"; };
3452
05D8B3571E8E1D7C00E5819A /* SnapLayout_ExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SnapLayout_ExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3553
05D8B35B1E8E1D7C00E5819A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3654
05D8B3611E8E1F7F00E5819A /* SnapConfigTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnapConfigTests.swift; sourceTree = "<group>"; };
@@ -73,6 +91,44 @@
7391
/* End PBXFrameworksBuildPhase section */
7492

7593
/* Begin PBXGroup section */
94+
053493ED1EBD4A1700D9F89D /* Cells */ = {
95+
isa = PBXGroup;
96+
children = (
97+
057099501EBD7B7F00D6EF71 /* AdjacentHorizontalTableViewCell.swift */,
98+
053493F01EBD4E7300D9F89D /* AdjacentVerticalTableViewCell.swift */,
99+
05B6D15F1EBC434500715D40 /* PriorityTableViewCell.swift */,
100+
053493EB1EBD486B00D9F89D /* SizeTableViewCell.swift */,
101+
05B6D1631EBC48CA00715D40 /* TitleTableViewCell.swift */,
102+
05B6D15B1EBC3B3400715D40 /* WelcomeTableViewCell.swift */,
103+
);
104+
name = Cells;
105+
sourceTree = "<group>";
106+
};
107+
053493EE1EBD4A2D00D9F89D /* VC */ = {
108+
isa = PBXGroup;
109+
children = (
110+
05B6D15D1EBC3E6F00715D40 /* IndexManager.swift */,
111+
607FACD71AFB9204008FA782 /* ViewController.swift */,
112+
);
113+
name = VC;
114+
sourceTree = "<group>";
115+
};
116+
053493EF1EBD4A3400D9F89D /* Extension */ = {
117+
isa = PBXGroup;
118+
children = (
119+
05B6D1611EBC438300715D40 /* UITableViewExtension.swift */,
120+
);
121+
name = Extension;
122+
sourceTree = "<group>";
123+
};
124+
057099541EBD7D4B00D6EF71 /* Style */ = {
125+
isa = PBXGroup;
126+
children = (
127+
057099521EBD7D3000D6EF71 /* Style.swift */,
128+
);
129+
name = Style;
130+
sourceTree = "<group>";
131+
};
76132
05D8B3581E8E1D7C00E5819A /* SnapLayout_ExampleTests */ = {
77133
isa = PBXGroup;
78134
children = (
@@ -120,11 +176,11 @@
120176
607FACD21AFB9204008FA782 /* Example for SnapLayout */ = {
121177
isa = PBXGroup;
122178
children = (
123-
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
124-
607FACD71AFB9204008FA782 /* ViewController.swift */,
125-
607FACDC1AFB9204008FA782 /* Images.xcassets */,
126-
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
179+
053493EE1EBD4A2D00D9F89D /* VC */,
180+
053493ED1EBD4A1700D9F89D /* Cells */,
127181
607FACD31AFB9204008FA782 /* Supporting Files */,
182+
053493EF1EBD4A3400D9F89D /* Extension */,
183+
057099541EBD7D4B00D6EF71 /* Style */,
128184
);
129185
name = "Example for SnapLayout";
130186
path = SnapLayout;
@@ -133,6 +189,9 @@
133189
607FACD31AFB9204008FA782 /* Supporting Files */ = {
134190
isa = PBXGroup;
135191
children = (
192+
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
193+
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
194+
607FACDC1AFB9204008FA782 /* Images.xcassets */,
136195
607FACD41AFB9204008FA782 /* Info.plist */,
137196
);
138197
name = "Supporting Files";
@@ -370,8 +429,17 @@
370429
isa = PBXSourcesBuildPhase;
371430
buildActionMask = 2147483647;
372431
files = (
432+
05B6D15E1EBC3E6F00715D40 /* IndexManager.swift in Sources */,
373433
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
374434
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
435+
053493EC1EBD486B00D9F89D /* SizeTableViewCell.swift in Sources */,
436+
053493F11EBD4E7300D9F89D /* AdjacentVerticalTableViewCell.swift in Sources */,
437+
05B6D1621EBC438300715D40 /* UITableViewExtension.swift in Sources */,
438+
05B6D1641EBC48CA00715D40 /* TitleTableViewCell.swift in Sources */,
439+
05B6D1601EBC434500715D40 /* PriorityTableViewCell.swift in Sources */,
440+
05B6D15C1EBC3B3400715D40 /* WelcomeTableViewCell.swift in Sources */,
441+
057099511EBD7B7F00D6EF71 /* AdjacentHorizontalTableViewCell.swift in Sources */,
442+
057099531EBD7D3000D6EF71 /* Style.swift in Sources */,
375443
);
376444
runOnlyForDeploymentPostprocessing = 0;
377445
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// AdjacentHorizontalTableViewCell.swift
3+
// SnapLayout
4+
//
5+
// Created by Satinder Singh on 5/5/17.
6+
// Copyright © 2017 CocoaPods. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import SnapLayout
11+
12+
/// Displays two views adjacent to one another horizontally
13+
internal final class AdjacentHorizontalTableViewCell: TitleTableViewCell {
14+
15+
fileprivate let leadingLabelConfig = SnapConfig(top: 48, leading: 16, bottom: 24)
16+
17+
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
18+
super.init(style: style, reuseIdentifier: reuseIdentifier)
19+
titleLabel.text = "Adjacent Horizontal"
20+
setupLabels()
21+
}
22+
23+
required init?(coder aDecoder: NSCoder) {
24+
super.init(coder: aDecoder)
25+
}
26+
27+
fileprivate func setupLabels() {
28+
let leadingLabel = Style.subtitleLabel(text: "Leading Label")
29+
contentView.addSubview(leadingLabel)
30+
leadingLabel.snap(constants: leadingLabelConfig)
31+
32+
let trailingLabel = Style.subtitleLabel(text: "Trailing Label")
33+
contentView.addSubview(trailingLabel)
34+
trailingLabel
35+
.snap(leadingView: leadingLabel, constant: 16)
36+
.snap(to: leadingLabel, top: 0)
37+
}
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// AdjacentVerticalTableViewCell.swift
3+
// SnapLayout
4+
//
5+
// Created by Satinder Singh on 5/5/17.
6+
// Copyright © 2017 CocoaPods. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import SnapLayout
11+
12+
/// Displays two views adjacent to one another vertically
13+
internal final class AdjacentVerticalTableViewCell: TitleTableViewCell {
14+
15+
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
16+
super.init(style: style, reuseIdentifier: reuseIdentifier)
17+
titleLabel.text = "Adjacent Vertical Views"
18+
setupSubtitleLabel()
19+
}
20+
21+
fileprivate func setupSubtitleLabel() {
22+
let subtitleLabel = Style.subtitleLabel(text: "This label has an adjacent constraint to the title label above. It also has three"
23+
+ " additional constraints to the superview for leading, bottom, and trailing.")
24+
contentView.addSubview(subtitleLabel)
25+
subtitleLabel
26+
.snap(topView: titleLabel, constant: 16) // adjacent constraint
27+
.snap(leading: 48, bottom: 8, trailing: 48)
28+
}
29+
30+
required init?(coder aDecoder: NSCoder) {
31+
super.init(coder: aDecoder)
32+
}
33+
34+
}

Example/SnapLayout/AppDelegate.swift

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1616

1717
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
19+
application.isStatusBarHidden = true
1920
window = UIWindow(frame: UIScreen.main.bounds)
2021
window?.rootViewController = ViewController()
2122
window?.makeKeyAndVisible()

Example/SnapLayout/IndexManager.swift

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// IndexManager.swift
3+
// SnapLayout
4+
//
5+
// Created by Satinder Singh on 5/4/17.
6+
// Copyright © 2017 CocoaPods. All rights reserved.
7+
//
8+
9+
/// Manages Tableview logic of which cell to display within `ViewController`
10+
internal enum IndexManager {
11+
12+
/// Displays `WelcomeTableViewCell`
13+
case welcome
14+
15+
/// Displays `PriorityTableViewCell`
16+
case priority
17+
18+
/// Displays `SizeTableViewCell`
19+
case size
20+
21+
/// Displays `AdjacentVerticalTableViewCell`
22+
case adjacentVertical
23+
24+
/// Displays `AdjacentHorizontalTableViewCell`
25+
case adjacentHorizontal
26+
27+
}

Example/SnapLayout/Info.plist

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<array>
2929
<string>armv7</string>
3030
</array>
31+
<key>UIViewControllerBasedStatusBarAppearance</key>
32+
<false/>
3133
<key>UISupportedInterfaceOrientations</key>
3234
<array>
3335
<string>UIInterfaceOrientationPortrait</string>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// PriorityTableViewCell.swift
3+
// SnapLayout
4+
//
5+
// Created by Satinder Singh on 5/4/17.
6+
// Copyright © 2017 CocoaPods. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
/// Displays rectangle view with a constraint whose priority is updated
12+
class PriorityTableViewCell: TitleTableViewCell {
13+
14+
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
15+
super.init(style: style, reuseIdentifier: reuseIdentifier)
16+
titleLabel.text = "Priority Changing"
17+
setup()
18+
}
19+
20+
required init?(coder aDecoder: NSCoder) {
21+
super.init(coder: aDecoder)
22+
}
23+
24+
fileprivate func setup() {
25+
let rectangleView = UIView()
26+
rectangleView.backgroundColor = .red
27+
contentView.addSubview(rectangleView)
28+
29+
// Snaps square view by pinning to all 4 sides (activated constraints)
30+
// Then creates an inactive height constraint whose priority is updated before being activated through `squareViewSnapManager`
31+
// Updating height priority to avoid following runtime warning
32+
// http://stackoverflow.com/questions/28410309/strange-uiview-encapsulated-layout-height-error
33+
let squareViewSnapManager = rectangleView
34+
.snap(top: 48, leading: 16, bottom: 16, trailing: 16)
35+
.snap(height: 40, isActive: false)
36+
squareViewSnapManager.height?.priority = 999
37+
squareViewSnapManager.height?.isActive = true
38+
39+
let circleView = UIView()
40+
circleView.backgroundColor = .green
41+
rectangleView.addSubview(circleView)
42+
// snaps width, height constraints and centering circle
43+
circleView.snap(width: 26, height: 26, centerX: 0, centerY: 0)
44+
circleView.layer.cornerRadius = 13
45+
}
46+
47+
}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// SizeTableViewCell.swift
3+
// SnapLayout
4+
//
5+
// Created by Satinder Singh on 5/5/17.
6+
// Copyright © 2017 CocoaPods. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import SnapLayout
11+
12+
/// Shows how to snap two views horizontally and vertically
13+
internal final class SizeTableViewCell: TitleTableViewCell {
14+
15+
/// Static height for AdjacentVerticalTableViewCell
16+
static let height = CGFloat(100)
17+
18+
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
19+
super.init(style: style, reuseIdentifier: reuseIdentifier)
20+
titleLabel.text = "Sizing views"
21+
let redView = UIView()
22+
redView.backgroundColor = .red
23+
contentView.addSubview(redView)
24+
25+
// snaps leading, bottom, .25 of contentView width, and half the height of contentView
26+
redView.snap(leading: 0, bottom: 0)
27+
.snapWidth(to: contentView, multiplier: 0.4)
28+
.snapHeight(to: contentView, multiplier: 0.5)
29+
30+
let greenView = UIView()
31+
greenView.backgroundColor = .green
32+
contentView.addSubview(greenView)
33+
34+
// snaps bottom, trailing, and matches width and height of redView
35+
greenView.snap(bottom: 0, trailing: 0)
36+
.snapWidth(to: redView)
37+
.snapHeight(to: redView)
38+
}
39+
40+
required init?(coder aDecoder: NSCoder) {
41+
super.init(coder: aDecoder)
42+
}
43+
44+
}

Example/SnapLayout/Style.swift

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// Style.swift
3+
// SnapLayout
4+
//
5+
// Created by Satinder Singh on 5/5/17.
6+
// Copyright © 2017 CocoaPods. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
/// Various Styles for labels
12+
struct Style {
13+
14+
/// Builder for titleLabels
15+
///
16+
/// - Parameter text: String to update text value (default nil)
17+
/// - Returns: UILabel initalized with text, font, 0 lines, and center alignment
18+
static func titleLabel(text: String? = nil) -> UILabel {
19+
let titleLabel = UILabel()
20+
titleLabel.text = text
21+
titleLabel.font = UIFont(name: "AvenirNext-DemiBold", size: 20)
22+
titleLabel.numberOfLines = 0
23+
titleLabel.textAlignment = .center
24+
return titleLabel
25+
}
26+
27+
/// Builder for subtitleLabel
28+
///
29+
/// - Parameter text: String to update text value (default nil)
30+
/// - Returns: UILabel initalized with text, font, 0 lines, and center alignment
31+
static func subtitleLabel(text: String? = nil) -> UILabel {
32+
let subtitleLabel = UILabel()
33+
subtitleLabel.text = text
34+
subtitleLabel.font = UIFont(name: "Avenir-Book", size: 15)
35+
subtitleLabel.numberOfLines = 0
36+
subtitleLabel.textAlignment = .center
37+
return subtitleLabel
38+
}
39+
}

0 commit comments

Comments
 (0)