Skip to content

Commit 6de1538

Browse files
author
Baris Sencan
committed
Merge pull request #5 from isair/feature/many-features
Many Features
2 parents 9ad9e07 + 8cd1138 commit 6de1538

File tree

8 files changed

+265
-1
lines changed

8 files changed

+265
-1
lines changed

ManualLayout.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
/* Begin PBXBuildFile section */
1010
5F67BC0A1A9D43FE00347483 /* FastAccessTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC091A9D43FE00347483 /* FastAccessTests.swift */; };
1111
5F67BC3F1A9E970300347483 /* UIViewController+LayoutGuides.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC3E1A9E970300347483 /* UIViewController+LayoutGuides.swift */; };
12+
5F67BC4C1A9FAB4B00347483 /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC4B1A9FAB4B00347483 /* Operators.swift */; };
13+
5F67BC4E1A9FB1A600347483 /* OperatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC4D1A9FB1A600347483 /* OperatorTests.swift */; };
14+
5F67BC501A9FDDD900347483 /* HelperFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC4F1A9FDDD900347483 /* HelperFunctions.swift */; };
15+
5F67BC521A9FE35C00347483 /* HelperFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC511A9FE35C00347483 /* HelperFunctionTests.swift */; };
1216
5F875C581A9BC8BF003CACDD /* Enums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C571A9BC8BF003CACDD /* Enums.swift */; };
1317
5F875C5B1A9BCBB2003CACDD /* UIView+ManualLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C5A1A9BCBB2003CACDD /* UIView+ManualLayout.swift */; };
1418
5F875C5F1A9BD55D003CACDD /* ManualLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */; };
@@ -34,6 +38,10 @@
3438
/* Begin PBXFileReference section */
3539
5F67BC091A9D43FE00347483 /* FastAccessTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FastAccessTests.swift; sourceTree = "<group>"; };
3640
5F67BC3E1A9E970300347483 /* UIViewController+LayoutGuides.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+LayoutGuides.swift"; sourceTree = "<group>"; };
41+
5F67BC4B1A9FAB4B00347483 /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = "<group>"; };
42+
5F67BC4D1A9FB1A600347483 /* OperatorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OperatorTests.swift; sourceTree = "<group>"; };
43+
5F67BC4F1A9FDDD900347483 /* HelperFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HelperFunctions.swift; sourceTree = "<group>"; };
44+
5F67BC511A9FE35C00347483 /* HelperFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HelperFunctionTests.swift; sourceTree = "<group>"; };
3745
5F875C571A9BC8BF003CACDD /* Enums.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Enums.swift; sourceTree = "<group>"; };
3846
5F875C5A1A9BCBB2003CACDD /* UIView+ManualLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+ManualLayout.swift"; sourceTree = "<group>"; };
3947
5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManualLayout.swift; sourceTree = "<group>"; };
@@ -91,6 +99,8 @@
9199
children = (
92100
5FB4CBEE1A9BBE7500C2FB4F /* ManualLayout.h */,
93101
5F875C571A9BC8BF003CACDD /* Enums.swift */,
102+
5F67BC4B1A9FAB4B00347483 /* Operators.swift */,
103+
5F67BC4F1A9FDDD900347483 /* HelperFunctions.swift */,
94104
5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */,
95105
5F875C681A9BE99F003CACDD /* CALayer+FastAccess.swift */,
96106
5F875C6E1A9BFE01003CACDD /* CALayer+ManualLayout.swift */,
@@ -113,6 +123,8 @@
113123
5FB4CBF81A9BBE7500C2FB4F /* ManualLayoutTests */ = {
114124
isa = PBXGroup;
115125
children = (
126+
5F67BC4D1A9FB1A600347483 /* OperatorTests.swift */,
127+
5F67BC511A9FE35C00347483 /* HelperFunctionTests.swift */,
116128
5F67BC091A9D43FE00347483 /* FastAccessTests.swift */,
117129
5FB4CBFB1A9BBE7500C2FB4F /* ManualLayoutTests.swift */,
118130
5F875C641A9BE2D3003CACDD /* UIViewManualLayoutTests.swift */,
@@ -238,9 +250,11 @@
238250
files = (
239251
5F875C691A9BE99F003CACDD /* CALayer+FastAccess.swift in Sources */,
240252
5F67BC3F1A9E970300347483 /* UIViewController+LayoutGuides.swift in Sources */,
253+
5F67BC501A9FDDD900347483 /* HelperFunctions.swift in Sources */,
241254
5F875C5F1A9BD55D003CACDD /* ManualLayout.swift in Sources */,
242255
5F875C5B1A9BCBB2003CACDD /* UIView+ManualLayout.swift in Sources */,
243256
5F875C6D1A9BFC7E003CACDD /* UIView+FastAccess.swift in Sources */,
257+
5F67BC4C1A9FAB4B00347483 /* Operators.swift in Sources */,
244258
5F875C581A9BC8BF003CACDD /* Enums.swift in Sources */,
245259
5F875C6F1A9BFE01003CACDD /* CALayer+ManualLayout.swift in Sources */,
246260
);
@@ -250,7 +264,9 @@
250264
isa = PBXSourcesBuildPhase;
251265
buildActionMask = 2147483647;
252266
files = (
267+
5F67BC521A9FE35C00347483 /* HelperFunctionTests.swift in Sources */,
253268
5F875C651A9BE2D3003CACDD /* UIViewManualLayoutTests.swift in Sources */,
269+
5F67BC4E1A9FB1A600347483 /* OperatorTests.swift in Sources */,
254270
5F67BC0A1A9D43FE00347483 /* FastAccessTests.swift in Sources */,
255271
5FB4CBFC1A9BBE7500C2FB4F /* ManualLayoutTests.swift in Sources */,
256272
);

ManualLayout/HelperFunctions.swift

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// Functions.swift
3+
// ManualLayout
4+
//
5+
// Created by Baris Sencan on 26/02/15.
6+
// Copyright (c) 2015 Baris Sencan. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
//MARK: - Insetting
12+
13+
public func inset(view: UIView, amount: CGFloat) -> CGRect {
14+
return inset(view.frame, amount)
15+
}
16+
17+
public func inset(layer: CALayer, amount: CGFloat) -> CGRect {
18+
return inset(layer.frame, amount)
19+
}
20+
21+
public func inset(rect: CGRect, amount: CGFloat) -> CGRect {
22+
return CGRectInset(rect, amount, amount)
23+
}
24+
25+
public func inset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect {
26+
return inset(view.frame, dx, dy)
27+
}
28+
29+
public func inset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect {
30+
return inset(layer.frame, dx, dy)
31+
}
32+
33+
public func inset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect {
34+
return CGRectInset(rect, dx, dy)
35+
}
36+
37+
public func inset(view: UIView, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect {
38+
return inset(view.frame, top, left, bottom, right)
39+
}
40+
41+
public func inset(layer: CALayer, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect {
42+
return inset(layer.frame, top, left, bottom, right)
43+
}
44+
45+
public func inset(rect: CGRect, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect {
46+
return CGRect(
47+
x: rect.origin.x + left,
48+
y: rect.origin.y + top,
49+
width: rect.size.width - left - right,
50+
height: rect.size.height - top - bottom)
51+
}
52+
53+
// MARK: - Offsetting
54+
55+
public func offset(view: UIView, amount: CGFloat) -> CGRect {
56+
return offset(view.frame, amount)
57+
}
58+
59+
public func offset(layer: CALayer, amount: CGFloat) -> CGRect {
60+
return offset(layer.frame, amount)
61+
}
62+
63+
public func offset(rect: CGRect, amount: CGFloat) -> CGRect {
64+
return CGRectOffset(rect, amount, amount)
65+
}
66+
67+
public func offset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect {
68+
return offset(view.frame, dx, dy)
69+
}
70+
71+
public func offset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect {
72+
return offset(layer.frame, dx, dy)
73+
}
74+
75+
public func offset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect {
76+
return CGRectOffset(rect, dx, dy)
77+
}

ManualLayout/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.2.1</string>
18+
<string>0.3.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

ManualLayout/Operators.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// OperatorOverloads.swift
3+
// ManualLayout
4+
//
5+
// Created by Baris Sencan on 26/02/15.
6+
// Copyright (c) 2015 Baris Sencan. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
infix operator =~ { associativity right precedence 150 }
12+
13+
public func =~ (inout point: CGPoint, pointTuple: (CGFloat, CGFloat)) -> CGPoint {
14+
point = CGPoint(x: pointTuple.0, y: pointTuple.1)
15+
return point
16+
}
17+
18+
public func =~ (inout size: CGSize, sizeTuple: (CGFloat, CGFloat)) -> CGSize {
19+
size = CGSize(width: sizeTuple.0, height: sizeTuple.1)
20+
return size
21+
}
22+
23+
public func =~ (inout rect: CGRect, rectTuple: (CGFloat, CGFloat, CGFloat, CGFloat)) -> CGRect {
24+
rect = CGRect(x: rectTuple.0, y: rectTuple.1, width: rectTuple.2, height: rectTuple.3)
25+
return rect
26+
}

ManualLayout/UIViewController+LayoutGuides.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ public extension UIViewController {
1414
return topLayoutGuide.length
1515
}
1616

17+
public var right: CGFloat { // For convenience.
18+
return view.width
19+
}
20+
1721
public var bottom: CGFloat {
1822
return view.height - bottomLayoutGuide.length
1923
}
24+
25+
public var left: CGFloat { // For convenience.
26+
return 0
27+
}
2028
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// HelperFunctionTests.swift
3+
// ManualLayout
4+
//
5+
// Created by Baris Sencan on 26/02/15.
6+
// Copyright (c) 2015 Baris Sencan. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import XCTest
11+
import ManualLayout
12+
13+
class HelperFunctionTests: XCTestCase {
14+
var view = UIView(frame: CGRectZero)
15+
let defaultFrame = CGRect(x: 1, y: 3, width: 6, height: 8)
16+
17+
override func setUp() {
18+
view.frame = defaultFrame
19+
}
20+
21+
func testInsetSingleArg() {
22+
view.frame = inset(view, 1)
23+
XCTAssertEqual(
24+
view.frame,
25+
CGRect(x: 2, y: 4, width: 4, height: 6),
26+
"insetting with amount should inset correctly")
27+
}
28+
29+
func testInsetTwoArg() {
30+
view.frame = inset(view, 1, 2)
31+
XCTAssertEqual(
32+
view.frame,
33+
CGRect(x: 2, y: 5, width: 4, height: 4),
34+
"insetting with dx and dy should inset correctly")
35+
}
36+
37+
func testInsetFourArg() {
38+
view.frame = inset(view, 1, 2, 3, 4)
39+
XCTAssertEqual(
40+
view.frame,
41+
CGRect(x: 3, y: 4, width: 0, height: 4),
42+
"insetting with four arguments should inset correctly")
43+
}
44+
45+
func testOffsetSingleArg() {
46+
view.frame = offset(view, 1)
47+
XCTAssertEqual(
48+
view.frame,
49+
CGRect(x: 2, y: 4, width: 6, height: 8),
50+
"offsetting with amount should offset correctly")
51+
}
52+
53+
func testOffsetTwoArg() {
54+
view.frame = offset(view, 1, 2)
55+
XCTAssertEqual(
56+
view.frame,
57+
CGRect(x: 2, y: 5, width: 6, height: 8),
58+
"offsetting with dx and dy should offset correctly")
59+
}
60+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// OperatorTests.swift
3+
// ManualLayout
4+
//
5+
// Created by Baris Sencan on 26/02/15.
6+
// Copyright (c) 2015 Baris Sencan. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import XCTest
11+
import ManualLayout
12+
13+
class OperatorTests: XCTestCase {
14+
var view = UIView(frame: CGRectZero)
15+
16+
override func setUp() {
17+
view.frame = CGRectZero
18+
}
19+
20+
func testPointAssignment() {
21+
view.origin =~ (1, 3)
22+
XCTAssertEqual(view.origin, CGPoint(x: 1, y: 3), "origin should be at (1, 3)")
23+
}
24+
25+
func testSizeAssignment() {
26+
view.size =~ (5, 7)
27+
XCTAssertEqual(view.size, CGSize(width: 5, height: 7), "size should be (5, 7)")
28+
}
29+
30+
func testRectAssignment() {
31+
view.frame =~ (1, 3, 5, 7)
32+
XCTAssertEqual(
33+
view.frame,
34+
CGRect(x: 1, y: 3, width: 5, height: 7),
35+
"frame should be at (1, 3) and of size (5, 7)")
36+
}
37+
}

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,47 @@ So basically, *setting a normal edge's position drags the whole view along with
6666

6767
```swift
6868
var top: CGFloat // Top layout guide y coordinate. Read-only.
69+
var right: CGFloat // Equal to the width of the controller's view. Read-only. For convenience.
6970
var bottom: CGFloat // Bottom layout guide y coordinate. Read-only.
71+
var left: CGFloat // Always equal to 0. Read-only. For convenience.
72+
```
73+
74+
###Helper Methods
75+
76+
```swift
77+
func inset(view: UIView, amount: CGFloat) -> CGRect
78+
func inset(layer: CALayer, amount: CGFloat) -> CGRect
79+
func inset(rect: CGRect, amount: CGFloat) -> CGRect
80+
81+
func inset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect
82+
func inset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect
83+
func inset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect
84+
85+
func inset(view: UIView, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect
86+
func inset(layer: CALayer, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect
87+
func inset(rect: CGRect, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect
88+
```
89+
90+
```swift
91+
func offset(view: UIView, amount: CGFloat) -> CGRect
92+
func offset(layer: CALayer, amount: CGFloat) -> CGRect
93+
func offset(rect: CGRect, amount: CGFloat) -> CGRect
94+
95+
func offset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect
96+
func offset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect
97+
func offset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect {
98+
```
99+
100+
These functions never modify the view/layer/rectangle they are passed.
101+
102+
###Smart Assign Operator
103+
104+
The smart assign operator `=~` has only one job; to make your life easier.
105+
106+
```swift
107+
someView.origin =~ (0, 20)
108+
anotherView.size =~ (100, 100)
109+
yetAnotherView.frame =~ (0, 120, view.width, 100)
70110
```
71111

72112
###CALayer/UIView Methods

0 commit comments

Comments
 (0)