From 3dacc0398afa1f91101e37cd436a3feeed55513e Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Thu, 26 Feb 2015 11:27:11 -0800 Subject: [PATCH 1/9] Convenience edges for controllers --- ManualLayout/UIViewController+LayoutGuides.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ManualLayout/UIViewController+LayoutGuides.swift b/ManualLayout/UIViewController+LayoutGuides.swift index 20a4b9b..128e4f9 100644 --- a/ManualLayout/UIViewController+LayoutGuides.swift +++ b/ManualLayout/UIViewController+LayoutGuides.swift @@ -14,7 +14,15 @@ public extension UIViewController { return topLayoutGuide.length } + public var right: CGFloat { // For convenience. + return view.width + } + public var bottom: CGFloat { return view.height - bottomLayoutGuide.length } + + public var left: CGFloat { // For convenience. + return 0 + } } From 3f0ce6fd4c92b09a8109f174e70c8d810f33b3ce Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Thu, 26 Feb 2015 12:02:06 -0800 Subject: [PATCH 2/9] Size and point assignment operators --- ManualLayout.xcodeproj/project.pbxproj | 8 +++++++ ManualLayout/Operators.swift | 21 +++++++++++++++++++ ManualLayoutTests/OperatorTests.swift | 29 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 ManualLayout/Operators.swift create mode 100644 ManualLayoutTests/OperatorTests.swift diff --git a/ManualLayout.xcodeproj/project.pbxproj b/ManualLayout.xcodeproj/project.pbxproj index dbc75f6..7f0b8a9 100644 --- a/ManualLayout.xcodeproj/project.pbxproj +++ b/ManualLayout.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 5F67BC0A1A9D43FE00347483 /* FastAccessTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC091A9D43FE00347483 /* FastAccessTests.swift */; }; 5F67BC3F1A9E970300347483 /* UIViewController+LayoutGuides.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC3E1A9E970300347483 /* UIViewController+LayoutGuides.swift */; }; + 5F67BC4C1A9FAB4B00347483 /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC4B1A9FAB4B00347483 /* Operators.swift */; }; + 5F67BC4E1A9FB1A600347483 /* OperatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC4D1A9FB1A600347483 /* OperatorTests.swift */; }; 5F875C581A9BC8BF003CACDD /* Enums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C571A9BC8BF003CACDD /* Enums.swift */; }; 5F875C5B1A9BCBB2003CACDD /* UIView+ManualLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C5A1A9BCBB2003CACDD /* UIView+ManualLayout.swift */; }; 5F875C5F1A9BD55D003CACDD /* ManualLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */; }; @@ -34,6 +36,8 @@ /* Begin PBXFileReference section */ 5F67BC091A9D43FE00347483 /* FastAccessTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FastAccessTests.swift; sourceTree = ""; }; 5F67BC3E1A9E970300347483 /* UIViewController+LayoutGuides.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+LayoutGuides.swift"; sourceTree = ""; }; + 5F67BC4B1A9FAB4B00347483 /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = ""; }; + 5F67BC4D1A9FB1A600347483 /* OperatorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OperatorTests.swift; sourceTree = ""; }; 5F875C571A9BC8BF003CACDD /* Enums.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Enums.swift; sourceTree = ""; }; 5F875C5A1A9BCBB2003CACDD /* UIView+ManualLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+ManualLayout.swift"; sourceTree = ""; }; 5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManualLayout.swift; sourceTree = ""; }; @@ -91,6 +95,7 @@ children = ( 5FB4CBEE1A9BBE7500C2FB4F /* ManualLayout.h */, 5F875C571A9BC8BF003CACDD /* Enums.swift */, + 5F67BC4B1A9FAB4B00347483 /* Operators.swift */, 5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */, 5F875C681A9BE99F003CACDD /* CALayer+FastAccess.swift */, 5F875C6E1A9BFE01003CACDD /* CALayer+ManualLayout.swift */, @@ -113,6 +118,7 @@ 5FB4CBF81A9BBE7500C2FB4F /* ManualLayoutTests */ = { isa = PBXGroup; children = ( + 5F67BC4D1A9FB1A600347483 /* OperatorTests.swift */, 5F67BC091A9D43FE00347483 /* FastAccessTests.swift */, 5FB4CBFB1A9BBE7500C2FB4F /* ManualLayoutTests.swift */, 5F875C641A9BE2D3003CACDD /* UIViewManualLayoutTests.swift */, @@ -241,6 +247,7 @@ 5F875C5F1A9BD55D003CACDD /* ManualLayout.swift in Sources */, 5F875C5B1A9BCBB2003CACDD /* UIView+ManualLayout.swift in Sources */, 5F875C6D1A9BFC7E003CACDD /* UIView+FastAccess.swift in Sources */, + 5F67BC4C1A9FAB4B00347483 /* Operators.swift in Sources */, 5F875C581A9BC8BF003CACDD /* Enums.swift in Sources */, 5F875C6F1A9BFE01003CACDD /* CALayer+ManualLayout.swift in Sources */, ); @@ -251,6 +258,7 @@ buildActionMask = 2147483647; files = ( 5F875C651A9BE2D3003CACDD /* UIViewManualLayoutTests.swift in Sources */, + 5F67BC4E1A9FB1A600347483 /* OperatorTests.swift in Sources */, 5F67BC0A1A9D43FE00347483 /* FastAccessTests.swift in Sources */, 5FB4CBFC1A9BBE7500C2FB4F /* ManualLayoutTests.swift in Sources */, ); diff --git a/ManualLayout/Operators.swift b/ManualLayout/Operators.swift new file mode 100644 index 0000000..c168810 --- /dev/null +++ b/ManualLayout/Operators.swift @@ -0,0 +1,21 @@ +// +// OperatorOverloads.swift +// ManualLayout +// +// Created by Baris Sencan on 26/02/15. +// Copyright (c) 2015 Baris Sencan. All rights reserved. +// + +import Foundation + + infix operator =~ { associativity right precedence 150 } + +public func =~ (inout point: CGPoint, pointTuple: (CGFloat, CGFloat)) -> CGPoint { + point = CGPoint(x: pointTuple.0, y: pointTuple.1) + return point +} + +public func =~ (inout size: CGSize, sizeTuple: (CGFloat, CGFloat)) -> CGSize { + size = CGSize(width: sizeTuple.0, height: sizeTuple.1) + return size +} diff --git a/ManualLayoutTests/OperatorTests.swift b/ManualLayoutTests/OperatorTests.swift new file mode 100644 index 0000000..1e0c599 --- /dev/null +++ b/ManualLayoutTests/OperatorTests.swift @@ -0,0 +1,29 @@ +// +// OperatorTests.swift +// ManualLayout +// +// Created by Baris Sencan on 26/02/15. +// Copyright (c) 2015 Baris Sencan. All rights reserved. +// + +import Foundation +import XCTest +import ManualLayout + +class OperatorTests: XCTestCase { + var view = UIView(frame: CGRectZero) + + override func setUp() { + view.frame = CGRectZero + } + + func testPointAssignment() { + view.origin =~ (1, 3) + XCTAssertEqual(view.origin, CGPoint(x: 1, y: 3), "origin should be at (1, 3)") + } + + func testSizeAssignment() { + view.size =~ (5, 7) + XCTAssertEqual(view.size, CGSize(width: 5, height: 7), "size should be (5, 7)") + } +} \ No newline at end of file From fa2247cc5a8a51579fa34c9ec9d2fb5519b0cc62 Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Thu, 26 Feb 2015 12:08:05 -0800 Subject: [PATCH 3/9] Short rect assignment --- ManualLayout/Operators.swift | 5 +++++ ManualLayoutTests/OperatorTests.swift | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/ManualLayout/Operators.swift b/ManualLayout/Operators.swift index c168810..9bf525f 100644 --- a/ManualLayout/Operators.swift +++ b/ManualLayout/Operators.swift @@ -19,3 +19,8 @@ public func =~ (inout size: CGSize, sizeTuple: (CGFloat, CGFloat)) -> CGSize { size = CGSize(width: sizeTuple.0, height: sizeTuple.1) return size } + +public func =~ (inout rect: CGRect, rectTuple: (CGFloat, CGFloat, CGFloat, CGFloat)) -> CGRect { + rect = CGRect(x: rectTuple.0, y: rectTuple.1, width: rectTuple.2, height: rectTuple.3) + return rect +} diff --git a/ManualLayoutTests/OperatorTests.swift b/ManualLayoutTests/OperatorTests.swift index 1e0c599..6a2a418 100644 --- a/ManualLayoutTests/OperatorTests.swift +++ b/ManualLayoutTests/OperatorTests.swift @@ -26,4 +26,12 @@ class OperatorTests: XCTestCase { view.size =~ (5, 7) XCTAssertEqual(view.size, CGSize(width: 5, height: 7), "size should be (5, 7)") } + + func testRectAssignment() { + view.frame =~ (1, 3, 5, 7) + XCTAssertEqual( + view.frame, + CGRect(x: 1, y: 3, width: 5, height: 7), + "frame should be at (1, 3) and of size (5, 7)") + } } \ No newline at end of file From d5f0c1f666955fdf8f7673dc9b9446230b3290ab Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Thu, 26 Feb 2015 15:40:07 -0800 Subject: [PATCH 4/9] Add inset and offset functions --- ManualLayout.xcodeproj/project.pbxproj | 8 +++ ManualLayout/HelperFunctions.swift | 77 +++++++++++++++++++++ ManualLayoutTests/HelperFunctionTests.swift | 28 ++++++++ 3 files changed, 113 insertions(+) create mode 100644 ManualLayout/HelperFunctions.swift create mode 100644 ManualLayoutTests/HelperFunctionTests.swift diff --git a/ManualLayout.xcodeproj/project.pbxproj b/ManualLayout.xcodeproj/project.pbxproj index 7f0b8a9..8ef7951 100644 --- a/ManualLayout.xcodeproj/project.pbxproj +++ b/ManualLayout.xcodeproj/project.pbxproj @@ -11,6 +11,8 @@ 5F67BC3F1A9E970300347483 /* UIViewController+LayoutGuides.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC3E1A9E970300347483 /* UIViewController+LayoutGuides.swift */; }; 5F67BC4C1A9FAB4B00347483 /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC4B1A9FAB4B00347483 /* Operators.swift */; }; 5F67BC4E1A9FB1A600347483 /* OperatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC4D1A9FB1A600347483 /* OperatorTests.swift */; }; + 5F67BC501A9FDDD900347483 /* HelperFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC4F1A9FDDD900347483 /* HelperFunctions.swift */; }; + 5F67BC521A9FE35C00347483 /* HelperFunctionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC511A9FE35C00347483 /* HelperFunctionTests.swift */; }; 5F875C581A9BC8BF003CACDD /* Enums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C571A9BC8BF003CACDD /* Enums.swift */; }; 5F875C5B1A9BCBB2003CACDD /* UIView+ManualLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C5A1A9BCBB2003CACDD /* UIView+ManualLayout.swift */; }; 5F875C5F1A9BD55D003CACDD /* ManualLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */; }; @@ -38,6 +40,8 @@ 5F67BC3E1A9E970300347483 /* UIViewController+LayoutGuides.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+LayoutGuides.swift"; sourceTree = ""; }; 5F67BC4B1A9FAB4B00347483 /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = ""; }; 5F67BC4D1A9FB1A600347483 /* OperatorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OperatorTests.swift; sourceTree = ""; }; + 5F67BC4F1A9FDDD900347483 /* HelperFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HelperFunctions.swift; sourceTree = ""; }; + 5F67BC511A9FE35C00347483 /* HelperFunctionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HelperFunctionTests.swift; sourceTree = ""; }; 5F875C571A9BC8BF003CACDD /* Enums.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Enums.swift; sourceTree = ""; }; 5F875C5A1A9BCBB2003CACDD /* UIView+ManualLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+ManualLayout.swift"; sourceTree = ""; }; 5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManualLayout.swift; sourceTree = ""; }; @@ -96,6 +100,7 @@ 5FB4CBEE1A9BBE7500C2FB4F /* ManualLayout.h */, 5F875C571A9BC8BF003CACDD /* Enums.swift */, 5F67BC4B1A9FAB4B00347483 /* Operators.swift */, + 5F67BC4F1A9FDDD900347483 /* HelperFunctions.swift */, 5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */, 5F875C681A9BE99F003CACDD /* CALayer+FastAccess.swift */, 5F875C6E1A9BFE01003CACDD /* CALayer+ManualLayout.swift */, @@ -119,6 +124,7 @@ isa = PBXGroup; children = ( 5F67BC4D1A9FB1A600347483 /* OperatorTests.swift */, + 5F67BC511A9FE35C00347483 /* HelperFunctionTests.swift */, 5F67BC091A9D43FE00347483 /* FastAccessTests.swift */, 5FB4CBFB1A9BBE7500C2FB4F /* ManualLayoutTests.swift */, 5F875C641A9BE2D3003CACDD /* UIViewManualLayoutTests.swift */, @@ -244,6 +250,7 @@ files = ( 5F875C691A9BE99F003CACDD /* CALayer+FastAccess.swift in Sources */, 5F67BC3F1A9E970300347483 /* UIViewController+LayoutGuides.swift in Sources */, + 5F67BC501A9FDDD900347483 /* HelperFunctions.swift in Sources */, 5F875C5F1A9BD55D003CACDD /* ManualLayout.swift in Sources */, 5F875C5B1A9BCBB2003CACDD /* UIView+ManualLayout.swift in Sources */, 5F875C6D1A9BFC7E003CACDD /* UIView+FastAccess.swift in Sources */, @@ -257,6 +264,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5F67BC521A9FE35C00347483 /* HelperFunctionTests.swift in Sources */, 5F875C651A9BE2D3003CACDD /* UIViewManualLayoutTests.swift in Sources */, 5F67BC4E1A9FB1A600347483 /* OperatorTests.swift in Sources */, 5F67BC0A1A9D43FE00347483 /* FastAccessTests.swift in Sources */, diff --git a/ManualLayout/HelperFunctions.swift b/ManualLayout/HelperFunctions.swift new file mode 100644 index 0000000..82b69f0 --- /dev/null +++ b/ManualLayout/HelperFunctions.swift @@ -0,0 +1,77 @@ +// +// Functions.swift +// ManualLayout +// +// Created by Baris Sencan on 26/02/15. +// Copyright (c) 2015 Baris Sencan. All rights reserved. +// + +import UIKit + +//MARK: - Insetting + +public func inset(view: UIView, amount: CGFloat) -> CGRect { + return inset(view.frame, amount) +} + +public func inset(layer: CALayer, amount: CGFloat) -> CGRect { + return inset(layer.frame, amount) +} + +public func inset(rect: CGRect, amount: CGFloat) -> CGRect { + return CGRectInset(rect, amount, amount) +} + +public func inset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect { + return inset(view.frame, dx, dy) +} + +public func inset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect { + return inset(layer.frame, dx, dy) +} + +public func inset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect { + return CGRectInset(rect, dx, dy) +} + +public func inset(view: UIView, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect { + return inset(view.frame, top, right, bottom, left) +} + +public func inset(layer: CALayer, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect { + return inset(layer.frame, top, right, bottom, left) +} + +public func inset(rect: CGRect, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect { + return CGRect( + x: rect.origin.x + left, + y: rect.origin.y + top, + width: rect.size.width - left - right, + height: rect.size.height - top - bottom) +} + +// MARK: - Offsetting + +public func offset(view: UIView, amount: CGFloat) -> CGRect { + return offset(view.frame, amount) +} + +public func offset(layer: CALayer, amount: CGFloat) -> CGRect { + return offset(layer.frame, amount) +} + +public func offset(rect: CGRect, amount: CGFloat) -> CGRect { + return CGRectOffset(rect, amount, amount) +} + +public func offset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect { + return offset(view.frame, dx, dy) +} + +public func offset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect { + return offset(layer.frame, dx, dy) +} + +public func offset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect { + return CGRectOffset(rect, dx, dy) +} diff --git a/ManualLayoutTests/HelperFunctionTests.swift b/ManualLayoutTests/HelperFunctionTests.swift new file mode 100644 index 0000000..5b87741 --- /dev/null +++ b/ManualLayoutTests/HelperFunctionTests.swift @@ -0,0 +1,28 @@ +// +// HelperFunctionTests.swift +// ManualLayout +// +// Created by Baris Sencan on 26/02/15. +// Copyright (c) 2015 Baris Sencan. All rights reserved. +// + +import Foundation +import XCTest +import ManualLayout + +class HelperFunctionTests: XCTestCase { + var view = UIView(frame: CGRectZero) + let defaultFrame = CGRect(x: 1, y: 3, width: 6, height: 8) + + override func setUp() { + view.frame = defaultFrame + } + + func testInset() { + + } + + func testOffset() { + + } +} \ No newline at end of file From 50d2f2e16a5ef0f569dea8fbbc1b536b369d366b Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Thu, 26 Feb 2015 15:56:42 -0800 Subject: [PATCH 5/9] Test helper functions --- ManualLayoutTests/HelperFunctionTests.swift | 38 +++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/ManualLayoutTests/HelperFunctionTests.swift b/ManualLayoutTests/HelperFunctionTests.swift index 5b87741..64b0330 100644 --- a/ManualLayoutTests/HelperFunctionTests.swift +++ b/ManualLayoutTests/HelperFunctionTests.swift @@ -18,11 +18,43 @@ class HelperFunctionTests: XCTestCase { view.frame = defaultFrame } - func testInset() { - + func testInsetSingleArg() { + view.frame = inset(view, 1) + XCTAssertEqual( + view.frame, + CGRect(x: 2, y: 4, width: 4, height: 6), + "insetting with amount should inset correctly") } - func testOffset() { + func testInsetTwoArg() { + view.frame = inset(view, 1, 2) + XCTAssertEqual( + view.frame, + CGRect(x: 2, y: 5, width: 4, height: 4), + "insetting with dx and dy should inset correctly") + } + + func testInsetFourArg() { + view.frame = inset(view, 1, 2, 3, 4) + XCTAssertEqual( + view.frame, + CGRect(x: 3, y: 4, width: 0, height: 4), + "insetting with four arguments should inset correctly") + } + + func testOffsetSingleArg() { + view.frame = offset(view, 1) + XCTAssertEqual( + view.frame, + CGRect(x: 2, y: 4, width: 6, height: 8), + "offsetting with amount should offset correctly") + } + func testOffsetTwoArg() { + view.frame = offset(view, 1, 2) + XCTAssertEqual( + view.frame, + CGRect(x: 2, y: 5, width: 6, height: 8), + "offsetting with dx and dy should offset correctly") } } \ No newline at end of file From bfb61d80b9bbd383e5947062196dbe57033e6172 Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Thu, 26 Feb 2015 15:56:51 -0800 Subject: [PATCH 6/9] Fix helper functions --- ManualLayout/HelperFunctions.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ManualLayout/HelperFunctions.swift b/ManualLayout/HelperFunctions.swift index 82b69f0..0a92e89 100644 --- a/ManualLayout/HelperFunctions.swift +++ b/ManualLayout/HelperFunctions.swift @@ -35,11 +35,11 @@ public func inset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect { } public func inset(view: UIView, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect { - return inset(view.frame, top, right, bottom, left) + return inset(view.frame, top, left, bottom, right) } public func inset(layer: CALayer, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect { - return inset(layer.frame, top, right, bottom, left) + return inset(layer.frame, top, left, bottom, right) } public func inset(rect: CGRect, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect { From 5fd25f1069310c0e58775d6a2498be7e5ae9b1e0 Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Thu, 26 Feb 2015 15:57:01 -0800 Subject: [PATCH 7/9] Fix typo and import --- ManualLayout/Operators.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ManualLayout/Operators.swift b/ManualLayout/Operators.swift index 9bf525f..77107a2 100644 --- a/ManualLayout/Operators.swift +++ b/ManualLayout/Operators.swift @@ -6,9 +6,9 @@ // Copyright (c) 2015 Baris Sencan. All rights reserved. // -import Foundation +import UIKit - infix operator =~ { associativity right precedence 150 } +infix operator =~ { associativity right precedence 150 } public func =~ (inout point: CGPoint, pointTuple: (CGFloat, CGFloat)) -> CGPoint { point = CGPoint(x: pointTuple.0, y: pointTuple.1) From 1d4ad62f12fe06086fc42afd99670b346693f0ba Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Thu, 26 Feb 2015 16:10:50 -0800 Subject: [PATCH 8/9] Document new features --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 8151089..b8de670 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,47 @@ So basically, *setting a normal edge's position drags the whole view along with ```swift var top: CGFloat // Top layout guide y coordinate. Read-only. +var right: CGFloat // Equal to the width of the controller's view. Read-only. For convenience. var bottom: CGFloat // Bottom layout guide y coordinate. Read-only. +var left: CGFloat // Always equal to 0. Read-only. For convenience. +``` + +###Helper Methods + +```swift +func inset(view: UIView, amount: CGFloat) -> CGRect +func inset(layer: CALayer, amount: CGFloat) -> CGRect +func inset(rect: CGRect, amount: CGFloat) -> CGRect + +func inset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect +func inset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect +func inset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect + +func inset(view: UIView, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect +func inset(layer: CALayer, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect +func inset(rect: CGRect, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect +``` + +```swift +func offset(view: UIView, amount: CGFloat) -> CGRect +func offset(layer: CALayer, amount: CGFloat) -> CGRect +func offset(rect: CGRect, amount: CGFloat) -> CGRect + +func offset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect +func offset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect +func offset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect { +``` + +These functions never modify the view/layer/rectangle they are passed. + +###Smart Assign Operator + +The smart assign operator `=~` has only one job; to make your life easier. + +```swift +someView.origin =~ (0, 20) +anotherView.size =~ (100, 100) +yetAnotherView.frame =~ (0, 120, view.width, 100) ``` ###CALayer/UIView Methods From 8cd11382aad0e1b0f40bfd4891fd27856ae1fc9f Mon Sep 17 00:00:00 2001 From: Baris Sencan Date: Thu, 26 Feb 2015 16:11:22 -0800 Subject: [PATCH 9/9] Increment version number --- ManualLayout/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ManualLayout/Info.plist b/ManualLayout/Info.plist index ba03b3a..f953bfd 100644 --- a/ManualLayout/Info.plist +++ b/ManualLayout/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.2.1 + 0.3.0 CFBundleSignature ???? CFBundleVersion