Skip to content

Commit 740ba4d

Browse files
author
Luc Dion
authored
Merge pull request #10 from mirego/remove_uiview_extension_method_and_split_file
Removed UIView extensions properties
2 parents 4d0f13c + 7485b92 commit 740ba4d

File tree

5 files changed

+438
-294
lines changed

5 files changed

+438
-294
lines changed

MCSwiftLayout.xcodeproj/project.pbxproj

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
249EFE841E64FB4C00165E39 /* MCSwiftLayout.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 249EFE7A1E64FB4C00165E39 /* MCSwiftLayout.framework */; };
2323
249EFE891E64FB4C00165E39 /* MCSwiftLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 249EFE881E64FB4C00165E39 /* MCSwiftLayoutTests.swift */; };
2424
249EFE8B1E64FB4C00165E39 /* MCSwiftLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 249EFE7D1E64FB4C00165E39 /* MCSwiftLayout.h */; settings = {ATTRIBUTES = (Public, ); }; };
25+
DF11A3711E833F03008B33E5 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3701E833F03008B33E5 /* Types.swift */; };
26+
DF11A3781E834B32008B33E5 /* UIView+PinLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3771E834B32008B33E5 /* UIView+PinLayout.swift */; };
27+
DF11A37A1E834B3F008B33E5 /* Coordinates.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3791E834B3F008B33E5 /* Coordinates.swift */; };
2528
/* End PBXBuildFile section */
2629

2730
/* Begin PBXContainerItemProxy section */
@@ -60,11 +63,14 @@
6063
246D36471E6C46F50050F202 /* PinPointCoordinatesSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinPointCoordinatesSpec.swift; sourceTree = "<group>"; };
6164
2482908B1E78CFFC00667D08 /* RelativePositionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RelativePositionSpec.swift; sourceTree = "<group>"; };
6265
249EFE7A1E64FB4C00165E39 /* MCSwiftLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MCSwiftLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; };
63-
249EFE7D1E64FB4C00165E39 /* MCSwiftLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCSwiftLayout.h; sourceTree = "<group>"; };
64-
249EFE7E1E64FB4C00165E39 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
66+
249EFE7D1E64FB4C00165E39 /* MCSwiftLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = MCSwiftLayout.h; path = MCSwiftLayout/MCSwiftLayout.h; sourceTree = "<group>"; };
67+
249EFE7E1E64FB4C00165E39 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = MCSwiftLayout/Info.plist; sourceTree = "<group>"; };
6568
249EFE831E64FB4C00165E39 /* MCSwiftLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MCSwiftLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
6669
249EFE881E64FB4C00165E39 /* MCSwiftLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCSwiftLayoutTests.swift; sourceTree = "<group>"; };
6770
249EFE8A1E64FB4C00165E39 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
71+
DF11A3701E833F03008B33E5 /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = "<group>"; };
72+
DF11A3771E834B32008B33E5 /* UIView+PinLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIView+PinLayout.swift"; path = "Extensions/UIView+PinLayout.swift"; sourceTree = "<group>"; };
73+
DF11A3791E834B3F008B33E5 /* Coordinates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Coordinates.swift; path = Helpers/Coordinates.swift; sourceTree = "<group>"; };
6874
/* End PBXFileReference section */
6975

7076
/* Begin PBXFrameworksBuildPhase section */
@@ -102,6 +108,7 @@
102108
children = (
103109
249EFE7C1E64FB4C00165E39 /* MCSwiftLayout */,
104110
249EFE871E64FB4C00165E39 /* MCSwiftLayoutTests */,
111+
DF11A3741E834181008B33E5 /* Supporting Files */,
105112
249EFE7B1E64FB4C00165E39 /* Products */,
106113
138A1F602470415292B7194B /* Frameworks */,
107114
);
@@ -119,9 +126,10 @@
119126
249EFE7C1E64FB4C00165E39 /* MCSwiftLayout */ = {
120127
isa = PBXGroup;
121128
children = (
122-
249EFE7D1E64FB4C00165E39 /* MCSwiftLayout.h */,
129+
DF11A3751E834194008B33E5 /* Extensions */,
130+
DF11A3761E8341A2008B33E5 /* Helpers */,
123131
2439CC301E6659FA003326FB /* Layout.swift */,
124-
249EFE7E1E64FB4C00165E39 /* Info.plist */,
132+
DF11A3701E833F03008B33E5 /* Types.swift */,
125133
);
126134
path = MCSwiftLayout;
127135
sourceTree = "<group>";
@@ -142,6 +150,31 @@
142150
path = MCSwiftLayoutTests;
143151
sourceTree = "<group>";
144152
};
153+
DF11A3741E834181008B33E5 /* Supporting Files */ = {
154+
isa = PBXGroup;
155+
children = (
156+
249EFE7D1E64FB4C00165E39 /* MCSwiftLayout.h */,
157+
249EFE7E1E64FB4C00165E39 /* Info.plist */,
158+
);
159+
name = "Supporting Files";
160+
sourceTree = "<group>";
161+
};
162+
DF11A3751E834194008B33E5 /* Extensions */ = {
163+
isa = PBXGroup;
164+
children = (
165+
DF11A3771E834B32008B33E5 /* UIView+PinLayout.swift */,
166+
);
167+
name = Extensions;
168+
sourceTree = "<group>";
169+
};
170+
DF11A3761E8341A2008B33E5 /* Helpers */ = {
171+
isa = PBXGroup;
172+
children = (
173+
DF11A3791E834B3F008B33E5 /* Coordinates.swift */,
174+
);
175+
name = Helpers;
176+
sourceTree = "<group>";
177+
};
145178
/* End PBXGroup section */
146179

147180
/* Begin PBXHeadersBuildPhase section */
@@ -274,7 +307,10 @@
274307
isa = PBXSourcesBuildPhase;
275308
buildActionMask = 2147483647;
276309
files = (
310+
DF11A3711E833F03008B33E5 /* Types.swift in Sources */,
311+
DF11A3781E834B32008B33E5 /* UIView+PinLayout.swift in Sources */,
277312
2439CC311E6659FA003326FB /* Layout.swift in Sources */,
313+
DF11A37A1E834B3F008B33E5 /* Coordinates.swift in Sources */,
278314
);
279315
runOnlyForDeploymentPostprocessing = 0;
280316
};
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//
2+
// UIView+PinLayout.swift
3+
// MCSwiftLayout
4+
//
5+
// Created by Luc Dion on 2017-03-22.
6+
// Copyright © 2017 mcswiftlayyout.mirego.com. All rights reserved.
7+
//
8+
9+
import UIKit
10+
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 edge: EdgeList {
21+
return EdgeList(view: self)
22+
}
23+
24+
// func layout(with layout: Layout) {
25+
// layout.apply(onView: self)
26+
// }
27+
}
28+
29+
// Could be part of another GitHub repo
30+
//public extension UIView {
31+
/*public var top: CGFloat {
32+
get { return frame.origin.y }
33+
set { frame = CGRect(x: left, y: roundFloatToDisplayScale(newValue), width: width, height: height) }
34+
}
35+
36+
public var left: CGFloat {
37+
get { return frame.origin.x }
38+
set { frame = CGRect(x: roundFloatToDisplayScale(newValue), y: top, width: width, height: height) }
39+
}
40+
41+
public var bottom: CGFloat {
42+
get { return frame.maxY }
43+
set { height = roundFloatToDisplayScale(newValue - top) }
44+
}
45+
46+
public var right: CGFloat {
47+
get { return frame.maxX }
48+
set { width = roundFloatToDisplayScale(newValue - left) }
49+
}
50+
51+
public var hCenter: CGFloat {
52+
get { return left + (width / 2) }
53+
set { left = newValue - (width / 2) }
54+
}
55+
56+
public var vCenter: CGFloat {
57+
get { return top + (height / 2) }
58+
set { top = newValue - (height / 2) }
59+
}*/
60+
61+
/* public var topLeft: CGPoint {
62+
get { return CGPoint(x: left, y: top) }
63+
set {
64+
left = newValue.x
65+
top = newValue.y
66+
}
67+
}
68+
69+
public var topCenter: CGPoint {
70+
get { return CGPoint(x: hCenter, y: top) }
71+
set {
72+
left = newValue.x - (width / 2)
73+
top = newValue.y
74+
}
75+
}
76+
77+
public var topRight: CGPoint {
78+
get { return CGPoint(x: left + width, y: top) }
79+
set {
80+
left = newValue.x - width
81+
top = newValue.y
82+
}
83+
}
84+
85+
public var rightCenter: CGPoint {
86+
get { return CGPoint(x: left + width, y: vCenter) }
87+
set {
88+
left = newValue.x - width
89+
top = newValue.y - (width / 2)
90+
}
91+
}
92+
93+
public var centers: CGPoint {
94+
get { return CGPoint(x: hCenter, y: vCenter) }
95+
set {
96+
left = newValue.x - (width / 2)
97+
top = newValue.y - (width / 2)
98+
}
99+
}
100+
101+
public var leftCenter: CGPoint {
102+
get { return CGPoint(x: left, y: vCenter) }
103+
set {
104+
left = newValue.x
105+
top = newValue.y - (width / 2)
106+
}
107+
}
108+
109+
public var bottomLeft: CGPoint {
110+
get { return CGPoint(x: left, y: top + height) }
111+
set {
112+
left = newValue.x
113+
top = newValue.y - height
114+
}
115+
}
116+
117+
public var bottomCenter: CGPoint {
118+
get { return CGPoint(x: hCenter, y: top + height) }
119+
set {
120+
left = newValue.x - (width / 2)
121+
top = newValue.y - height
122+
}
123+
}
124+
125+
public var bottomRight: CGPoint {
126+
get { return CGPoint(x: left + width, y: top + height) }
127+
set {
128+
left = newValue.x - width
129+
top = newValue.y - height
130+
}
131+
} */
132+
133+
// public var size: CGSize {
134+
// get { return CGSize(width: width, height: height) }
135+
// set { frame = CGRect(x: left, y: top, width: ceilFloatToDisplayScale(newValue.width), height: ceilFloatToDisplayScale(newValue.height)) }
136+
// }
137+
//
138+
// public var width: CGFloat {
139+
// get { return frame.size.width }
140+
// set { frame = CGRect(x: left, y: top, width: ceilFloatToDisplayScale(newValue), height: height) }
141+
// }
142+
//
143+
// public var height: CGFloat {
144+
// get { return frame.size.height }
145+
// set { frame = CGRect(x: left, y: top, width: width, height: ceilFloatToDisplayScale(newValue)) }
146+
// }
147+
//}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// View.swift
3+
// MCSwiftLayout
4+
//
5+
// Created by Luc Dion on 2017-03-22.
6+
// Copyright © 2017 mcswiftlayyout.mirego.com. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
internal class Coordinates {
12+
// static func top(_ view: UIView) -> CGFloat {
13+
// return view.frame.origin.y
14+
// }
15+
//
16+
// static func left(_ view: UIView) -> CGFloat {
17+
// return view.frame.origin.x
18+
// }
19+
20+
static func bottom(_ view: UIView) -> CGFloat {
21+
return view.frame.maxY
22+
}
23+
24+
static func right(_ view: UIView) -> CGFloat {
25+
return view.frame.maxX
26+
}
27+
28+
static func hCenter(_ view: UIView) -> CGFloat {
29+
return view.frame.origin.x + (view.frame.size.width / 2)
30+
}
31+
32+
static func vCenter(_ view: UIView) -> CGFloat {
33+
return view.frame.origin.y + (view.frame.size.height / 2)
34+
}
35+
36+
// static func size(_ view: UIView) -> CGSize {
37+
// return view.frame.size
38+
// }
39+
// static func width(_ view: UIView) -> CGFloat {
40+
// return view.frame.size.width
41+
// }
42+
//
43+
// static func height(_ view: UIView) -> CGFloat {
44+
// return view.frame.size.height
45+
// }
46+
47+
static func topLeft(_ view: UIView) -> CGPoint {
48+
return CGPoint(x: view.frame.origin.x, y: view.frame.origin.y)
49+
}
50+
51+
static func topCenter(_ view: UIView) -> CGPoint {
52+
return CGPoint(x: hCenter(view), y: view.frame.origin.y)
53+
}
54+
55+
static func topRight(_ view: UIView) -> CGPoint {
56+
return CGPoint(x: view.frame.origin.x + view.frame.size.width, y: view.frame.origin.y)
57+
}
58+
59+
static func rightCenter(_ view: UIView) -> CGPoint {
60+
return CGPoint(x: view.frame.origin.x + view.frame.size.width, y: vCenter(view))
61+
}
62+
63+
static func center(_ view: UIView) -> CGPoint {
64+
return CGPoint(x: hCenter(view), y: vCenter(view))
65+
}
66+
67+
static func leftCenter(_ view: UIView) -> CGPoint {
68+
return CGPoint(x: view.frame.origin.x, y: vCenter(view))
69+
}
70+
71+
static func bottomLeft(_ view: UIView) -> CGPoint {
72+
return CGPoint(x: view.frame.origin.x, y: view.frame.origin.y + view.frame.size.height)
73+
}
74+
75+
static func bottomCenter(_ view: UIView) -> CGPoint {
76+
return CGPoint(x: hCenter(view), y: view.frame.origin.y + view.frame.size.height)
77+
}
78+
79+
static func bottomRight(_ view: UIView) -> CGPoint {
80+
return CGPoint(x: view.frame.origin.x + view.frame.size.width, y: view.frame.origin.y + view.frame.size.height)
81+
}
82+
83+
static let displayScale = UIScreen.main.scale
84+
85+
static func adjustRectToDisplayScale(_ rect: CGRect) -> CGRect {
86+
return CGRect(x: ceilFloatToDisplayScale(rect.origin.x),
87+
y: ceilFloatToDisplayScale(rect.origin.y),
88+
width: ceilFloatToDisplayScale(rect.size.width),
89+
height: ceilFloatToDisplayScale(rect.size.height))
90+
}
91+
92+
static func roundFloatToDisplayScale(_ pointValue: CGFloat) -> CGFloat {
93+
return (round(pointValue * displayScale) / displayScale)
94+
}
95+
96+
static func ceilFloatToDisplayScale(_ pointValue: CGFloat) -> CGFloat {
97+
return (round(pointValue * displayScale) / displayScale)
98+
}
99+
}

0 commit comments

Comments
 (0)