Skip to content

Commit cf61816

Browse files
author
Luc Dion
authored
Merge pull request #13 from mirego/add_PinLayout_protocol
Major rename + PinLayout protocol
2 parents 78ac697 + 8031d36 commit cf61816

File tree

25 files changed

+805
-716
lines changed

25 files changed

+805
-716
lines changed

MCSwiftLayout.xcodeproj/project.pbxproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
2419623A1E7F582C00A0466C /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 241962381E7F582C00A0466C /* Quick.framework */; };
1212
2419623C1E7F592800A0466C /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 241962371E7F582C00A0466C /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1313
2419623D1E7F592800A0466C /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 241962381E7F582C00A0466C /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
14-
2439CC311E6659FA003326FB /* Layout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2439CC301E6659FA003326FB /* Layout.swift */; };
1514
244C6E151E776A0C0074FC74 /* MarginsAndInsetsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 244C6E141E776A0C0074FC74 /* MarginsAndInsetsSpec.swift */; };
1615
2469C4FC1E74855D00073BEE /* PinEdgeCoordinateSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2469C4FB1E74855D00073BEE /* PinEdgeCoordinateSpec.swift */; };
1716
2469C5001E75D74000073BEE /* AdjustSizeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2469C4FF1E75D74000073BEE /* AdjustSizeSpec.swift */; };
@@ -25,6 +24,8 @@
2524
DF11A3711E833F03008B33E5 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3701E833F03008B33E5 /* Types.swift */; };
2625
DF11A3781E834B32008B33E5 /* UIView+PinLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3771E834B32008B33E5 /* UIView+PinLayout.swift */; };
2726
DF11A37A1E834B3F008B33E5 /* Coordinates.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3791E834B3F008B33E5 /* Coordinates.swift */; };
27+
DFC97CA51E8A8EB3001545D5 /* PinLayoutImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFC97CA41E8A8EB3001545D5 /* PinLayoutImpl.swift */; };
28+
DFC97CA71E8A8F2C001545D5 /* PinLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFC97CA61E8A8F2C001545D5 /* PinLayout.swift */; };
2829
/* End PBXBuildFile section */
2930

3031
/* Begin PBXContainerItemProxy section */
@@ -54,7 +55,6 @@
5455
/* Begin PBXFileReference section */
5556
241962371E7F582C00A0466C /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = "<group>"; };
5657
241962381E7F582C00A0466C /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/iOS/Quick.framework; sourceTree = "<group>"; };
57-
2439CC301E6659FA003326FB /* Layout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Layout.swift; sourceTree = "<group>"; };
5858
244C6E141E776A0C0074FC74 /* MarginsAndInsetsSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MarginsAndInsetsSpec.swift; sourceTree = "<group>"; };
5959
2469C4FB1E74855D00073BEE /* PinEdgeCoordinateSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinEdgeCoordinateSpec.swift; sourceTree = "<group>"; };
6060
2469C4FF1E75D74000073BEE /* AdjustSizeSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdjustSizeSpec.swift; sourceTree = "<group>"; };
@@ -71,6 +71,8 @@
7171
DF11A3701E833F03008B33E5 /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = "<group>"; };
7272
DF11A3771E834B32008B33E5 /* UIView+PinLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+PinLayout.swift"; sourceTree = "<group>"; };
7373
DF11A3791E834B3F008B33E5 /* Coordinates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Coordinates.swift; sourceTree = "<group>"; };
74+
DFC97CA41E8A8EB3001545D5 /* PinLayoutImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinLayoutImpl.swift; sourceTree = "<group>"; };
75+
DFC97CA61E8A8F2C001545D5 /* PinLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinLayout.swift; sourceTree = "<group>"; };
7476
/* End PBXFileReference section */
7577

7678
/* Begin PBXFrameworksBuildPhase section */
@@ -126,10 +128,11 @@
126128
249EFE7C1E64FB4C00165E39 /* MCSwiftLayout */ = {
127129
isa = PBXGroup;
128130
children = (
131+
DFC97CA61E8A8F2C001545D5 /* PinLayout.swift */,
132+
DFC97CA41E8A8EB3001545D5 /* PinLayoutImpl.swift */,
133+
DF11A3701E833F03008B33E5 /* Types.swift */,
129134
DF11A3751E834194008B33E5 /* Extensions */,
130135
DF11A3761E8341A2008B33E5 /* Helpers */,
131-
2439CC301E6659FA003326FB /* Layout.swift */,
132-
DF11A3701E833F03008B33E5 /* Types.swift */,
133136
);
134137
path = MCSwiftLayout;
135138
sourceTree = "<group>";
@@ -309,8 +312,9 @@
309312
files = (
310313
DF11A3711E833F03008B33E5 /* Types.swift in Sources */,
311314
DF11A3781E834B32008B33E5 /* UIView+PinLayout.swift in Sources */,
312-
2439CC311E6659FA003326FB /* Layout.swift in Sources */,
313315
DF11A37A1E834B3F008B33E5 /* Coordinates.swift in Sources */,
316+
DFC97CA71E8A8F2C001545D5 /* PinLayout.swift in Sources */,
317+
DFC97CA51E8A8EB3001545D5 /* PinLayoutImpl.swift in Sources */,
314318
);
315319
runOnlyForDeploymentPostprocessing = 0;
316320
};

MCSwiftLayout/Extensions/UIView+PinLayout.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,6 @@
88

99
import UIKit
1010

11-
public extension UIView {
12-
public var layout: Layout {
13-
return Layout(view: self)
14-
}
15-
16-
public var pin: PinList {
17-
return PinList(view: self)
18-
}
19-
20-
// public var pin: Layout {
21-
// return Layout(view: self)
22-
// }
23-
24-
public var edge: EdgeList {
25-
return EdgeList(view: self)
26-
}
27-
28-
// func layout(with layout: Layout) {
29-
// layout.apply(onView: self)
30-
// }
31-
}
32-
3311
// Could be part of another GitHub repo?
3412
public extension UIView {
3513
public var top: CGFloat {

MCSwiftLayout/PinLayout.swift

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//
2+
// PinLayout.swift
3+
// MCSwiftLayout
4+
//
5+
// Created by Luc Dion on 2017-03-28.
6+
// Copyright © 2017 mcswiftlayyout.mirego.com. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public extension UIView {
12+
public var pin: PinLayout {
13+
return PinLayoutImpl(view: self)
14+
}
15+
16+
public var anchor: PinList {
17+
return PinList(view: self)
18+
}
19+
20+
public var edge: EdgeList {
21+
return EdgeList(view: self)
22+
}
23+
}
24+
25+
public protocol PinLayout {
26+
@discardableResult func top(_ value: CGFloat) -> PinLayout
27+
@discardableResult func left(_ value: CGFloat) -> PinLayout
28+
@discardableResult func bottom(_ value: CGFloat) -> PinLayout
29+
@discardableResult func right(_ value: CGFloat) -> PinLayout
30+
31+
@discardableResult func top(to edge: VerticalEdge) -> PinLayout
32+
@discardableResult func left(to edge: HorizontalEdge) -> PinLayout
33+
@discardableResult func bottom(to edge: VerticalEdge) -> PinLayout
34+
@discardableResult func right(to edge: HorizontalEdge) -> PinLayout
35+
36+
@discardableResult func topLeft(to point: CGPoint) -> PinLayout
37+
@discardableResult func topLeft(to pin: Pin) -> PinLayout
38+
@discardableResult func topLeft() -> PinLayout
39+
40+
@discardableResult func topCenter(to point: CGPoint) -> PinLayout
41+
@discardableResult func topCenter(to pin: Pin) -> PinLayout
42+
@discardableResult func topCenter() -> PinLayout
43+
44+
@discardableResult func topRight(to point: CGPoint) -> PinLayout
45+
@discardableResult func topRight(to pin: Pin) -> PinLayout
46+
@discardableResult func topRight() -> PinLayout
47+
48+
@discardableResult func leftCenter(to point: CGPoint) -> PinLayout
49+
@discardableResult func leftCenter(to pin: Pin) -> PinLayout
50+
@discardableResult func leftCenter() -> PinLayout
51+
52+
@discardableResult func center(to point: CGPoint) -> PinLayout
53+
@discardableResult func center(to pin: Pin) -> PinLayout
54+
@discardableResult func center() -> PinLayout
55+
56+
@discardableResult func rightCenter(to point: CGPoint) -> PinLayout
57+
@discardableResult func rightCenter(to pin: Pin) -> PinLayout
58+
@discardableResult func rightCenter() -> PinLayout
59+
60+
@discardableResult func bottomLeft(to point: CGPoint) -> PinLayout
61+
@discardableResult func bottomLeft(to pin: Pin) -> PinLayout
62+
@discardableResult func bottomLeft() -> PinLayout
63+
64+
@discardableResult func bottomCenter(to point: CGPoint) -> PinLayout
65+
@discardableResult func bottomCenter(to pin: Pin) -> PinLayout
66+
@discardableResult func bottomCenter() -> PinLayout
67+
68+
@discardableResult func bottomRight(to point: CGPoint) -> PinLayout
69+
@discardableResult func bottomRight(to pin: Pin) -> PinLayout
70+
@discardableResult func bottomRight() -> PinLayout
71+
72+
@discardableResult func above(of relativeView: UIView) -> PinLayout
73+
@discardableResult func above(of relativeView: UIView, aligned: HorizontalAlignment) -> PinLayout
74+
@discardableResult func below(of relativeView: UIView) -> PinLayout
75+
@discardableResult func below(of relativeView: UIView, aligned: HorizontalAlignment) -> PinLayout
76+
@discardableResult func left(of relativeView: UIView) -> PinLayout
77+
@discardableResult func left(of relativeView: UIView, aligned: VerticalAlignment) -> PinLayout
78+
@discardableResult func right(of relativeView: UIView) -> PinLayout
79+
@discardableResult func right(of relativeView: UIView, aligned: VerticalAlignment) -> PinLayout
80+
81+
@discardableResult func width(_ width: CGFloat) -> PinLayout
82+
@discardableResult func width(percent: CGFloat) -> PinLayout
83+
@discardableResult func width(of view: UIView) -> PinLayout
84+
@discardableResult func height(_ height: CGFloat) -> PinLayout
85+
@discardableResult func height(percent: CGFloat) -> PinLayout
86+
@discardableResult func height(of view: UIView) -> PinLayout
87+
@discardableResult func size(_ size: CGSize) -> PinLayout
88+
@discardableResult func size(of view: UIView) -> PinLayout
89+
@discardableResult func sizeToFit() -> PinLayout
90+
91+
@discardableResult func margin(_ value: CGFloat) -> PinLayout
92+
@discardableResult func marginHorizontal(_ value: CGFloat) -> PinLayout
93+
@discardableResult func marginVertical(_ value: CGFloat) -> PinLayout
94+
@discardableResult func marginTop(_ value: CGFloat) -> PinLayout
95+
@discardableResult func marginLeft(_ value: CGFloat) -> PinLayout
96+
@discardableResult func marginBottom(_ value: CGFloat) -> PinLayout
97+
@discardableResult func marginRight(_ value: CGFloat) -> PinLayout
98+
99+
@discardableResult func inset(_ value: CGFloat) -> PinLayout
100+
@discardableResult func insetTop(_ value: CGFloat) -> PinLayout
101+
@discardableResult func insetLeft(_ value: CGFloat) -> PinLayout
102+
@discardableResult func insetBottom(_ value: CGFloat) -> PinLayout
103+
@discardableResult func insetRight(_ value: CGFloat) -> PinLayout
104+
@discardableResult func insetHorizontal(_ value: CGFloat) -> PinLayout
105+
@discardableResult func insetVertical(_ value: CGFloat) -> PinLayout
106+
}
107+
108+
// RELATIVE POSITION
109+
public enum HorizontalAlignment: String {
110+
case left
111+
case center
112+
case right
113+
}
114+
115+
public enum VerticalAlignment: String {
116+
case top
117+
case center
118+
case bottom
119+
}
120+
121+

0 commit comments

Comments
 (0)