From 8031d3673c287083af1b73380f93ae7b310c8bd0 Mon Sep 17 00:00:00 2001 From: Luc Dion Date: Tue, 28 Mar 2017 18:50:32 -0400 Subject: [PATCH] Major rename * Add PinLayout protocol & PinLayoutImpl * view.layout -> view.pin * view.pin -> view.anchor * pinXXXX -> xXXX --- MCSwiftLayout.xcodeproj/project.pbxproj | 14 +- .../Extensions/UIView+PinLayout.swift | 22 -- MCSwiftLayout/PinLayout.swift | 121 ++++++++ .../{Layout.swift => PinLayoutImpl.swift} | 279 ++++++++--------- MCSwiftLayout/Types.swift | 9 +- .../UI/Common/BasicView.swift | 2 +- .../UI/Main/MenuView.swift | 2 +- .../UI/Main/MenuViewController.swift | 2 +- .../BothEdgesSnappedView.swift | 284 +++++++++--------- .../ChainedLayoutView/ChainedLayoutView.swift | 18 +- .../MarginsAndInsetsView.swift | 74 ++--- .../MarginsAndPaddingsLeftRightView.swift | 38 +-- .../MarginsAndPaddingsLeftWidthView.swift | 38 +-- .../MultiRelativeView/MultiRelativeView.swift | 6 +- .../Tests/PinScrolling/PinScrollingView.swift | 10 +- .../UI/Tests/RelativeView/RelativeView.swift | 28 +- .../ValidateConflictsView.swift | 4 +- .../ViewExtensionsPositionningView.swift | 4 +- MCSwiftLayoutTests/AdjustSizeSpec.swift | 86 +++--- MCSwiftLayoutTests/BasicView.swift | 2 +- MCSwiftLayoutTests/MCSwiftLayoutTests.swift | 2 +- MCSwiftLayoutTests/MarginsAndInsetsSpec.swift | 148 ++++----- .../PinEdgeCoordinateSpec.swift | 64 ++-- .../PinPointCoordinatesSpec.swift | 200 ++++++------ MCSwiftLayoutTests/RelativePositionSpec.swift | 64 ++-- 25 files changed, 805 insertions(+), 716 deletions(-) create mode 100644 MCSwiftLayout/PinLayout.swift rename MCSwiftLayout/{Layout.swift => PinLayoutImpl.swift} (82%) diff --git a/MCSwiftLayout.xcodeproj/project.pbxproj b/MCSwiftLayout.xcodeproj/project.pbxproj index ca934b71..cc0f0b50 100644 --- a/MCSwiftLayout.xcodeproj/project.pbxproj +++ b/MCSwiftLayout.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 2419623A1E7F582C00A0466C /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 241962381E7F582C00A0466C /* Quick.framework */; }; 2419623C1E7F592800A0466C /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 241962371E7F582C00A0466C /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 2419623D1E7F592800A0466C /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 241962381E7F582C00A0466C /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 2439CC311E6659FA003326FB /* Layout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2439CC301E6659FA003326FB /* Layout.swift */; }; 244C6E151E776A0C0074FC74 /* MarginsAndInsetsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 244C6E141E776A0C0074FC74 /* MarginsAndInsetsSpec.swift */; }; 2469C4FC1E74855D00073BEE /* PinEdgeCoordinateSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2469C4FB1E74855D00073BEE /* PinEdgeCoordinateSpec.swift */; }; 2469C5001E75D74000073BEE /* AdjustSizeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2469C4FF1E75D74000073BEE /* AdjustSizeSpec.swift */; }; @@ -25,6 +24,8 @@ DF11A3711E833F03008B33E5 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3701E833F03008B33E5 /* Types.swift */; }; DF11A3781E834B32008B33E5 /* UIView+PinLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3771E834B32008B33E5 /* UIView+PinLayout.swift */; }; DF11A37A1E834B3F008B33E5 /* Coordinates.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF11A3791E834B3F008B33E5 /* Coordinates.swift */; }; + DFC97CA51E8A8EB3001545D5 /* PinLayoutImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFC97CA41E8A8EB3001545D5 /* PinLayoutImpl.swift */; }; + DFC97CA71E8A8F2C001545D5 /* PinLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFC97CA61E8A8F2C001545D5 /* PinLayout.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -54,7 +55,6 @@ /* Begin PBXFileReference section */ 241962371E7F582C00A0466C /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = ""; }; 241962381E7F582C00A0466C /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/iOS/Quick.framework; sourceTree = ""; }; - 2439CC301E6659FA003326FB /* Layout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Layout.swift; sourceTree = ""; }; 244C6E141E776A0C0074FC74 /* MarginsAndInsetsSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MarginsAndInsetsSpec.swift; sourceTree = ""; }; 2469C4FB1E74855D00073BEE /* PinEdgeCoordinateSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinEdgeCoordinateSpec.swift; sourceTree = ""; }; 2469C4FF1E75D74000073BEE /* AdjustSizeSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdjustSizeSpec.swift; sourceTree = ""; }; @@ -71,6 +71,8 @@ DF11A3701E833F03008B33E5 /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = ""; }; DF11A3771E834B32008B33E5 /* UIView+PinLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+PinLayout.swift"; sourceTree = ""; }; DF11A3791E834B3F008B33E5 /* Coordinates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Coordinates.swift; sourceTree = ""; }; + DFC97CA41E8A8EB3001545D5 /* PinLayoutImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinLayoutImpl.swift; sourceTree = ""; }; + DFC97CA61E8A8F2C001545D5 /* PinLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinLayout.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -126,10 +128,11 @@ 249EFE7C1E64FB4C00165E39 /* MCSwiftLayout */ = { isa = PBXGroup; children = ( + DFC97CA61E8A8F2C001545D5 /* PinLayout.swift */, + DFC97CA41E8A8EB3001545D5 /* PinLayoutImpl.swift */, + DF11A3701E833F03008B33E5 /* Types.swift */, DF11A3751E834194008B33E5 /* Extensions */, DF11A3761E8341A2008B33E5 /* Helpers */, - 2439CC301E6659FA003326FB /* Layout.swift */, - DF11A3701E833F03008B33E5 /* Types.swift */, ); path = MCSwiftLayout; sourceTree = ""; @@ -309,8 +312,9 @@ files = ( DF11A3711E833F03008B33E5 /* Types.swift in Sources */, DF11A3781E834B32008B33E5 /* UIView+PinLayout.swift in Sources */, - 2439CC311E6659FA003326FB /* Layout.swift in Sources */, DF11A37A1E834B3F008B33E5 /* Coordinates.swift in Sources */, + DFC97CA71E8A8F2C001545D5 /* PinLayout.swift in Sources */, + DFC97CA51E8A8EB3001545D5 /* PinLayoutImpl.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MCSwiftLayout/Extensions/UIView+PinLayout.swift b/MCSwiftLayout/Extensions/UIView+PinLayout.swift index 76d36bf3..08c5fe28 100644 --- a/MCSwiftLayout/Extensions/UIView+PinLayout.swift +++ b/MCSwiftLayout/Extensions/UIView+PinLayout.swift @@ -8,28 +8,6 @@ import UIKit -public extension UIView { - public var layout: Layout { - return Layout(view: self) - } - - public var pin: PinList { - return PinList(view: self) - } - -// public var pin: Layout { -// return Layout(view: self) -// } - - public var edge: EdgeList { - return EdgeList(view: self) - } - - // func layout(with layout: Layout) { - // layout.apply(onView: self) - // } -} - // Could be part of another GitHub repo? public extension UIView { public var top: CGFloat { diff --git a/MCSwiftLayout/PinLayout.swift b/MCSwiftLayout/PinLayout.swift new file mode 100644 index 00000000..3861a066 --- /dev/null +++ b/MCSwiftLayout/PinLayout.swift @@ -0,0 +1,121 @@ +// +// PinLayout.swift +// MCSwiftLayout +// +// Created by Luc Dion on 2017-03-28. +// Copyright Ā© 2017 mcswiftlayyout.mirego.com. All rights reserved. +// + +import Foundation + +public extension UIView { + public var pin: PinLayout { + return PinLayoutImpl(view: self) + } + + public var anchor: PinList { + return PinList(view: self) + } + + public var edge: EdgeList { + return EdgeList(view: self) + } +} + +public protocol PinLayout { + @discardableResult func top(_ value: CGFloat) -> PinLayout + @discardableResult func left(_ value: CGFloat) -> PinLayout + @discardableResult func bottom(_ value: CGFloat) -> PinLayout + @discardableResult func right(_ value: CGFloat) -> PinLayout + + @discardableResult func top(to edge: VerticalEdge) -> PinLayout + @discardableResult func left(to edge: HorizontalEdge) -> PinLayout + @discardableResult func bottom(to edge: VerticalEdge) -> PinLayout + @discardableResult func right(to edge: HorizontalEdge) -> PinLayout + + @discardableResult func topLeft(to point: CGPoint) -> PinLayout + @discardableResult func topLeft(to pin: Pin) -> PinLayout + @discardableResult func topLeft() -> PinLayout + + @discardableResult func topCenter(to point: CGPoint) -> PinLayout + @discardableResult func topCenter(to pin: Pin) -> PinLayout + @discardableResult func topCenter() -> PinLayout + + @discardableResult func topRight(to point: CGPoint) -> PinLayout + @discardableResult func topRight(to pin: Pin) -> PinLayout + @discardableResult func topRight() -> PinLayout + + @discardableResult func leftCenter(to point: CGPoint) -> PinLayout + @discardableResult func leftCenter(to pin: Pin) -> PinLayout + @discardableResult func leftCenter() -> PinLayout + + @discardableResult func center(to point: CGPoint) -> PinLayout + @discardableResult func center(to pin: Pin) -> PinLayout + @discardableResult func center() -> PinLayout + + @discardableResult func rightCenter(to point: CGPoint) -> PinLayout + @discardableResult func rightCenter(to pin: Pin) -> PinLayout + @discardableResult func rightCenter() -> PinLayout + + @discardableResult func bottomLeft(to point: CGPoint) -> PinLayout + @discardableResult func bottomLeft(to pin: Pin) -> PinLayout + @discardableResult func bottomLeft() -> PinLayout + + @discardableResult func bottomCenter(to point: CGPoint) -> PinLayout + @discardableResult func bottomCenter(to pin: Pin) -> PinLayout + @discardableResult func bottomCenter() -> PinLayout + + @discardableResult func bottomRight(to point: CGPoint) -> PinLayout + @discardableResult func bottomRight(to pin: Pin) -> PinLayout + @discardableResult func bottomRight() -> PinLayout + + @discardableResult func above(of relativeView: UIView) -> PinLayout + @discardableResult func above(of relativeView: UIView, aligned: HorizontalAlignment) -> PinLayout + @discardableResult func below(of relativeView: UIView) -> PinLayout + @discardableResult func below(of relativeView: UIView, aligned: HorizontalAlignment) -> PinLayout + @discardableResult func left(of relativeView: UIView) -> PinLayout + @discardableResult func left(of relativeView: UIView, aligned: VerticalAlignment) -> PinLayout + @discardableResult func right(of relativeView: UIView) -> PinLayout + @discardableResult func right(of relativeView: UIView, aligned: VerticalAlignment) -> PinLayout + + @discardableResult func width(_ width: CGFloat) -> PinLayout + @discardableResult func width(percent: CGFloat) -> PinLayout + @discardableResult func width(of view: UIView) -> PinLayout + @discardableResult func height(_ height: CGFloat) -> PinLayout + @discardableResult func height(percent: CGFloat) -> PinLayout + @discardableResult func height(of view: UIView) -> PinLayout + @discardableResult func size(_ size: CGSize) -> PinLayout + @discardableResult func size(of view: UIView) -> PinLayout + @discardableResult func sizeToFit() -> PinLayout + + @discardableResult func margin(_ value: CGFloat) -> PinLayout + @discardableResult func marginHorizontal(_ value: CGFloat) -> PinLayout + @discardableResult func marginVertical(_ value: CGFloat) -> PinLayout + @discardableResult func marginTop(_ value: CGFloat) -> PinLayout + @discardableResult func marginLeft(_ value: CGFloat) -> PinLayout + @discardableResult func marginBottom(_ value: CGFloat) -> PinLayout + @discardableResult func marginRight(_ value: CGFloat) -> PinLayout + + @discardableResult func inset(_ value: CGFloat) -> PinLayout + @discardableResult func insetTop(_ value: CGFloat) -> PinLayout + @discardableResult func insetLeft(_ value: CGFloat) -> PinLayout + @discardableResult func insetBottom(_ value: CGFloat) -> PinLayout + @discardableResult func insetRight(_ value: CGFloat) -> PinLayout + @discardableResult func insetHorizontal(_ value: CGFloat) -> PinLayout + @discardableResult func insetVertical(_ value: CGFloat) -> PinLayout +} + +// RELATIVE POSITION +public enum HorizontalAlignment: String { + case left + case center + case right +} + +public enum VerticalAlignment: String { + case top + case center + case bottom +} + + diff --git a/MCSwiftLayout/Layout.swift b/MCSwiftLayout/PinLayoutImpl.swift similarity index 82% rename from MCSwiftLayout/Layout.swift rename to MCSwiftLayout/PinLayoutImpl.swift index 9281320b..c43abef3 100644 --- a/MCSwiftLayout/Layout.swift +++ b/MCSwiftLayout/PinLayoutImpl.swift @@ -1,6 +1,5 @@ // -// Layout.swift -// MCLayoutExample +// PinLayout.swift // // Created by DION, Luc (MTL) on 2017-02-17. // Copyright Ā© 2017 Mirego. All rights reserved. @@ -8,11 +7,6 @@ import UIKit -//constrain(button1, button2) { button1, button2 in -// button1.right == button2.left - 12 -//} - - /* =============================================== QUESTIONS: @@ -113,7 +107,7 @@ import UIKit - margin(t:? = nil l:? = nil b:? = nil r:? = nil ) ?? - Unit tests TODO: - - pinTopLeft(to: Pin, of: UIView), pinTopCenter(to: Pin, of: UIView), ... + - pinTopLeft(to: Pin, of: UIView), topCenter(to: Pin, of: UIView), ... - margins and insets negatifs - With SwiftyAttributes, you can write the same thing like this: @@ -133,20 +127,21 @@ import UIKit viewA.pinTopLeft(to: viewB.pin.topLeft).margin(20) viewA.width(20).height(20) } + + //constrain(button1, button2) { button1, button2 in + // button1.right == button2.left - 12 + //} */ -fileprivate typealias Context = () -> String -fileprivate typealias Size = (width: CGFloat?, height: CGFloat?) - -public func pin(_ view: UIView) -> Layout { - return Layout(view: view) -} +//func pin(_ view: UIView) -> PinLayout { +// return Layout(view: view) +//} -public class Layout { +class PinLayoutImpl: PinLayout { #if DEBUG - public static var logConflicts = true + static var logConflicts = true #else - public static var logConflicts = false + static var logConflicts = false #endif // static var useBottomRightCssStyle = false @@ -176,7 +171,7 @@ public class Layout { fileprivate var shouldSizeToFit = false - public init(view: UIView) { + init(view: UIView) { self.view = view } @@ -188,35 +183,35 @@ public class Layout { // top, left, bottom, right // @discardableResult - public func top(_ value: CGFloat) -> Layout { + func top(_ value: CGFloat) -> PinLayout { setTop(value, context: { return "top(\(value))" }) return self } @discardableResult - public func left(_ value: CGFloat) -> Layout { + func left(_ value: CGFloat) -> PinLayout { setLeft(value, context: { return "left(\(value))" }) return self } @discardableResult - public func bottom(_ value: CGFloat) -> Layout { + func bottom(_ value: CGFloat) -> PinLayout { setBottom(value, context: { return "bottom(\(value))" }) return self } @discardableResult - public func right(_ value: CGFloat) -> Layout { + func right(_ value: CGFloat) -> PinLayout { setRight(value, context: { return "right(\(value))" }) return self } // - // pinTop, pinLeft, pinBottom, pinRight + // top, left, bottom, right // @discardableResult - public func pinTop(to edge: VerticalEdge) -> Layout { - func context() -> String { return "pinTop(to: \(edge.edgeType.rawValue), of: \(edge.view))" } + func top(to edge: VerticalEdge) -> PinLayout { + func context() -> String { return "top(to: \(edge.edgeType.rawValue), of: \(edge.view))" } if let coordinate = computeCoordinates(forEdge: edge.edgeType, of: edge.view, context: context) { setTop(coordinate.y, context: context) } @@ -224,8 +219,8 @@ public class Layout { } @discardableResult - public func pinLeft(to edge: HorizontalEdge) -> Layout { - func context() -> String { return "pinLeft(to: \(edge.edgeType.rawValue), of: \(edge.view))" } + func left(to edge: HorizontalEdge) -> PinLayout { + func context() -> String { return "left(to: \(edge.edgeType.rawValue), of: \(edge.view))" } if let coordinate = computeCoordinates(forEdge: edge.edgeType, of: edge.view, context: context) { setLeft(coordinate.x, context: context) } @@ -233,8 +228,8 @@ public class Layout { } @discardableResult - public func pinBottom(to edge: VerticalEdge) -> Layout { - func context() -> String { return "pinBottom(to: \(edge.edgeType.rawValue), of: \(edge.view))" } + func bottom(to edge: VerticalEdge) -> PinLayout { + func context() -> String { return "bottom(to: \(edge.edgeType.rawValue), of: \(edge.view))" } if let coordinate = computeCoordinates(forEdge: edge.edgeType, of: edge.view, context: context) { setBottom(coordinate.y, context: context) } @@ -242,8 +237,8 @@ public class Layout { } @discardableResult - public func pinRight(to edge: HorizontalEdge) -> Layout { - func context() -> String { return "pinRight(to: \(edge.edgeType.rawValue), of: \(edge.view))" } + func right(to edge: HorizontalEdge) -> PinLayout { + func context() -> String { return "right(to: \(edge.edgeType.rawValue), of: \(edge.view))" } if let coordinate = computeCoordinates(forEdge: edge.edgeType, of: edge.view, context: context) { setRight(coordinate.x, context: context) } @@ -253,19 +248,19 @@ public class Layout { // TODO: Add hCenter and vCenter // - // pinTopLeft, pinTopCenter, pinTopRight, - // pinLeftCenter, pinCenter, pinRightCenter, - // pinBottomLeft, pinBottomCenter, pinBottomRight, + // topLeft, topCenter, topRight, + // leftCenter, center, rightCenter, + // bottomLeft, bottomCenter, bottomRight, // @discardableResult - public func pinTopLeft(to point: CGPoint) -> Layout { - return setTopLeft(point, context: { return "pinTopLeft(to: CGPoint(x: \(point.x), y: \(point.y)))" }) + func topLeft(to point: CGPoint) -> PinLayout { + return setTopLeft(point, context: { return "topLeft(to: CGPoint(x: \(point.x), y: \(point.y)))" }) } /// Position the topLeft on the specified view's pin. @discardableResult - public func pinTopLeft(to pin: Pin) -> Layout { - func context() -> String { return "pinTopLeft(to: \(pin.pinType.rawValue), of: \(view))" } + func topLeft(to pin: Pin) -> PinLayout { + func context() -> String { return "topLeft(to: \(pin.pinType.rawValue), of: \(view))" } if let coordinates = computeCoordinates(forPin: pin.pinType, of: pin.view, context: context) { setTopLeft(coordinates, context: context) } @@ -274,8 +269,8 @@ public class Layout { /// Position on the topLeft corner of its parent. @discardableResult - public func pinTopLeft() -> Layout { - func context() -> String { return "pinTopLeft()" } + func topLeft() -> PinLayout { + func context() -> String { return "topLeft()" } if let layoutSuperview = validateLayoutSuperview(context: context) { if let coordinates = computeCoordinates(forPin: .topLeft, of: layoutSuperview, context: context) { setTopLeft(coordinates, context: context) @@ -285,14 +280,14 @@ public class Layout { } @discardableResult - public func pinTopCenter(to point: CGPoint) -> Layout { - return setTopCenter(point, context: { return "pinTopCenter(to: CGPoint(x: \(point.x), y: \(point.y)))" }) + func topCenter(to point: CGPoint) -> PinLayout { + return setTopCenter(point, context: { return "topCenter(to: CGPoint(x: \(point.x), y: \(point.y)))" }) } /// Position the topCenter on the specified view's pin. @discardableResult - public func pinTopCenter(to pin: Pin) -> Layout { - func context() -> String { return "pinTopCenter(to: \(pin.pinType.rawValue), of: \(view))" } + func topCenter(to pin: Pin) -> PinLayout { + func context() -> String { return "topCenter(to: \(pin.pinType.rawValue), of: \(view))" } if let coordinates = computeCoordinates(forPin: pin.pinType, of: pin.view, context: context) { setTopCenter(coordinates, context: context) } @@ -301,8 +296,8 @@ public class Layout { /// Position on the topCenter corner of its parent. @discardableResult - public func pinTopCenter() -> Layout { - func context() -> String { return "pinTopCenter()" } + func topCenter() -> PinLayout { + func context() -> String { return "topCenter()" } if let layoutSuperview = validateLayoutSuperview(context: context) { if let coordinates = computeCoordinates(forPin: .topCenter, of: layoutSuperview, context: context) { setTopCenter(coordinates, context: context) @@ -312,14 +307,14 @@ public class Layout { } @discardableResult - public func pinTopRight(to point: CGPoint) -> Layout { - return setTopRight(point, context: { return "pinTopRight(to: CGPoint(x: \(point.x), y: \(point.y)))" }) + func topRight(to point: CGPoint) -> PinLayout { + return setTopRight(point, context: { return "topRight(to: CGPoint(x: \(point.x), y: \(point.y)))" }) } /// Position the topRight on the specified view's pin. @discardableResult - public func pinTopRight(to pin: Pin) -> Layout { - func context() -> String { return "pinTopRight(to: \(pin.pinType.rawValue), of: \(view))" } + func topRight(to pin: Pin) -> PinLayout { + func context() -> String { return "topRight(to: \(pin.pinType.rawValue), of: \(view))" } if let coordinates = computeCoordinates(forPin: pin.pinType, of: pin.view, context: context) { setTopRight(coordinates, context: context) } @@ -328,8 +323,8 @@ public class Layout { /// Position on the topRight corner of its parent. @discardableResult - public func pinTopRight() -> Layout { - func context() -> String { return "pinTopRight()" } + func topRight() -> PinLayout { + func context() -> String { return "topRight()" } if let layoutSuperview = validateLayoutSuperview(context: context) { if let coordinates = computeCoordinates(forPin: .topRight, of: layoutSuperview, context: context) { setTopRight(coordinates, context: context) @@ -339,14 +334,14 @@ public class Layout { } @discardableResult - public func pinLeftCenter(to point: CGPoint) -> Layout { - return setLeftCenter(point, context: { return "pinLeftCenter(to: CGPoint(x: \(point.x), y: \(point.y)))" }) + func leftCenter(to point: CGPoint) -> PinLayout { + return setLeftCenter(point, context: { return "leftCenter(to: CGPoint(x: \(point.x), y: \(point.y)))" }) } /// Position the leftCenter on the specified view's pin. @discardableResult - public func pinLeftCenter(to pin: Pin) -> Layout { - func context() -> String { return "pinLeftCenter(to: \(pin.pinType.rawValue), of: \(view))" } + func leftCenter(to pin: Pin) -> PinLayout { + func context() -> String { return "leftCenter(to: \(pin.pinType.rawValue), of: \(view))" } if let coordinates = computeCoordinates(forPin: pin.pinType, of: pin.view, context: context) { setLeftCenter(coordinates, context: context) } @@ -355,8 +350,8 @@ public class Layout { /// Position on the leftCenter corner of its parent. @discardableResult - public func pinLeftCenter() -> Layout { - func context() -> String { return "pinLeftCenter()" } + func leftCenter() -> PinLayout { + func context() -> String { return "leftCenter()" } if let layoutSuperview = validateLayoutSuperview(context: context) { if let coordinates = computeCoordinates(forPin: .leftCenter, of: layoutSuperview, context: context) { setLeftCenter(coordinates, context: context) @@ -366,14 +361,14 @@ public class Layout { } @discardableResult - public func pinCenter(to point: CGPoint) -> Layout { - return setCenter(point, context: { return "pinCenter(to: CGPoint(x: \(point.x), y: \(point.y)))" }) + func center(to point: CGPoint) -> PinLayout { + return setCenter(point, context: { return "center(to: CGPoint(x: \(point.x), y: \(point.y)))" }) } /// Position the centers on the specified view's pin. @discardableResult - public func pinCenter(to pin: Pin) -> Layout { - func context() -> String { return "pinCenter(to: \(pin.pinType.rawValue), of: \(view))" } + func center(to pin: Pin) -> PinLayout { + func context() -> String { return "center(to: \(pin.pinType.rawValue), of: \(view))" } if let coordinates = computeCoordinates(forPin: pin.pinType, of: pin.view, context: context) { setCenter(coordinates, context: context) } @@ -381,8 +376,8 @@ public class Layout { } @discardableResult - public func pinCenter() -> Layout { - func context() -> String { return "pinCenter()" } + func center() -> PinLayout { + func context() -> String { return "center()" } if let layoutSuperview = validateLayoutSuperview(context: context) { if let coordinates = computeCoordinates(forPin: .center, of: layoutSuperview, context: context) { setCenter(coordinates, context: context) @@ -392,14 +387,14 @@ public class Layout { } @discardableResult - public func pinRightCenter(to point: CGPoint) -> Layout { - return setRightCenter(point, context: { return "pinRightCenter(to: CGPoint(x: \(point.x), y: \(point.y)))" }) + func rightCenter(to point: CGPoint) -> PinLayout { + return setRightCenter(point, context: { return "rightCenter(to: CGPoint(x: \(point.x), y: \(point.y)))" }) } /// Position the rightCenter on the specified view's pin. @discardableResult - public func pinRightCenter(to pin: Pin) -> Layout { - func context() -> String { return "pinRightCenter(to: \(pin.pinType.rawValue), of: \(view))" } + func rightCenter(to pin: Pin) -> PinLayout { + func context() -> String { return "rightCenter(to: \(pin.pinType.rawValue), of: \(view))" } if let coordinates = computeCoordinates(forPin: pin.pinType, of: pin.view, context: context) { setRightCenter(coordinates, context: context) } @@ -408,8 +403,8 @@ public class Layout { /// Position on the rightCenter corner of its parent. @discardableResult - public func pinRightCenter() -> Layout { - func context() -> String { return "pinRightCenter()" } + func rightCenter() -> PinLayout { + func context() -> String { return "rightCenter()" } if let layoutSuperview = validateLayoutSuperview(context: context) { if let coordinates = computeCoordinates(forPin: .rightCenter, of: layoutSuperview, context: context) { setRightCenter(coordinates, context: context) @@ -419,14 +414,14 @@ public class Layout { } @discardableResult - public func pinBottomLeft(to point: CGPoint) -> Layout { - return setBottomLeft(point, context: { return "pinBottomLeft(to: CGPoint(x: \(point.x), y: \(point.y)))" }) + func bottomLeft(to point: CGPoint) -> PinLayout { + return setBottomLeft(point, context: { return "bottomLeft(to: CGPoint(x: \(point.x), y: \(point.y)))" }) } /// Position the bottomLeft on the specified view's pin. @discardableResult - public func pinBottomLeft(to pin: Pin) -> Layout { - func context() -> String { return "pinBottomLeft(to: \(pin.pinType.rawValue), of: \(view))" } + func bottomLeft(to pin: Pin) -> PinLayout { + func context() -> String { return "bottomLeft(to: \(pin.pinType.rawValue), of: \(view))" } if let coordinates = computeCoordinates(forPin: pin.pinType, of: pin.view, context: context) { setBottomLeft(coordinates, context: context) } @@ -435,8 +430,8 @@ public class Layout { /// Position on the bottomLeft corner of its parent. @discardableResult - public func pinBottomLeft() -> Layout { - func context() -> String { return "pinBottomLeft()" } + func bottomLeft() -> PinLayout { + func context() -> String { return "bottomLeft()" } if let layoutSuperview = validateLayoutSuperview(context: context) { if let coordinates = computeCoordinates(forPin: .bottomLeft, of: layoutSuperview, context: context) { setBottomLeft(coordinates, context: context) @@ -446,14 +441,14 @@ public class Layout { } @discardableResult - public func pinBottomCenter(to point: CGPoint) -> Layout { - return setBottomCenter(point, context: { return "pinBottomCenter(to: CGPoint(x: \(point.x), y: \(point.y)))" }) + func bottomCenter(to point: CGPoint) -> PinLayout { + return setBottomCenter(point, context: { return "bottomCenter(to: CGPoint(x: \(point.x), y: \(point.y)))" }) } /// Position the bottomCenter on the specified view's pin. @discardableResult - public func pinBottomCenter(to pin: Pin) -> Layout { - func context() -> String { return "pinBottomCenter(to: \(pin.pinType.rawValue), of: \(view))" } + func bottomCenter(to pin: Pin) -> PinLayout { + func context() -> String { return "bottomCenter(to: \(pin.pinType.rawValue), of: \(view))" } if let coordinates = computeCoordinates(forPin: pin.pinType, of: pin.view, context: context) { setBottomCenter(coordinates, context: context) } @@ -462,8 +457,8 @@ public class Layout { /// Position on the bottomCenter corner of its parent. @discardableResult - public func pinBottomCenter() -> Layout { - func context() -> String { return "pinBottomCenter()" } + func bottomCenter() -> PinLayout { + func context() -> String { return "bottomCenter()" } if let layoutSuperview = validateLayoutSuperview(context: context) { if let coordinates = computeCoordinates(forPin: .bottomCenter, of: layoutSuperview, context: context) { setBottomCenter(coordinates, context: context) @@ -473,14 +468,14 @@ public class Layout { } @discardableResult - public func pinBottomRight(to point: CGPoint) -> Layout { - return setBottomRight(point, context: { return "pinBottomRight(to: CGPoint(x: \(point.x), y: \(point.y)))" }) + func bottomRight(to point: CGPoint) -> PinLayout { + return setBottomRight(point, context: { return "bottomRight(to: CGPoint(x: \(point.x), y: \(point.y)))" }) } /// Position the bottomRight on the specified view's pin. @discardableResult - public func pinBottomRight(to pin: Pin) -> Layout { - func context() -> String { return "pinBottomRight(to: \(pin.pinType.rawValue), of: \(view))" } + func bottomRight(to pin: Pin) -> PinLayout { + func context() -> String { return "bottomRight(to: \(pin.pinType.rawValue), of: \(view))" } if let coordinates = computeCoordinates(forPin: pin.pinType, of: pin.view, context: context) { setBottomRight(coordinates, context: context) } @@ -489,8 +484,8 @@ public class Layout { /// Position on the bottomRight corner of its parent. @discardableResult - public func pinBottomRight() -> Layout { - func context() -> String { return "pinBottomRight()" } + func bottomRight() -> PinLayout { + func context() -> String { return "bottomRight()" } if let layoutSuperview = validateLayoutSuperview(context: context) { if let coordinates = computeCoordinates(forPin: .bottomRight, of: layoutSuperview, context: context) { setBottomRight(coordinates, context: context) @@ -499,22 +494,9 @@ public class Layout { return self } - // RELATIVE POSITION - public enum HorizontalAlignment: String { - case left - case center - case right - } - - public enum VerticalAlignment: String { - case top - case center - case bottom - } - /// Set the view's bottom coordinate above of the specified view. @discardableResult - public func above(of relativeView: UIView) -> Layout { + func above(of relativeView: UIView) -> PinLayout { func context() -> String { return "below(of: \(view))" } if let coordinate = computeCoordinates(forEdge: .top, of: relativeView, context: context) { setBottom(coordinate.y, context: context) @@ -523,7 +505,7 @@ public class Layout { } @discardableResult - public func above(of relativeView: UIView, aligned: HorizontalAlignment) -> Layout { + func above(of relativeView: UIView, aligned: HorizontalAlignment) -> PinLayout { func context() -> String { return "above(of: \(view), aligned: \(aligned))" } switch aligned { @@ -545,7 +527,7 @@ public class Layout { /// Set the view's top coordinate below of the specified view. @discardableResult - public func below(of relativeView: UIView) -> Layout { + func below(of relativeView: UIView) -> PinLayout { func context() -> String { return "below(of: \(view))" } if let coordinate = computeCoordinates(forEdge: .bottom, of: relativeView, context: context) { setTop(coordinate.y, context: context) @@ -554,7 +536,7 @@ public class Layout { } @discardableResult - public func below(of relativeView: UIView, aligned: HorizontalAlignment) -> Layout { + func below(of relativeView: UIView, aligned: HorizontalAlignment) -> PinLayout { func context() -> String { return "below(of: \(view), aligned: \(aligned))" } switch aligned { @@ -576,7 +558,7 @@ public class Layout { /// Set the view's right coordinate left of the specified view. @discardableResult - public func left(of relativeView: UIView) -> Layout { + func left(of relativeView: UIView) -> PinLayout { func context() -> String { return "left(of: \(view))" } if let coordinate = computeCoordinates(forEdge: .left, of: relativeView, context: context) { setRight(coordinate.x, context: context) @@ -585,7 +567,7 @@ public class Layout { } @discardableResult - public func left(of relativeView: UIView, aligned: VerticalAlignment) -> Layout { + func left(of relativeView: UIView, aligned: VerticalAlignment) -> PinLayout { func context() -> String { return "left(of: \(view), aligned: \(aligned))" } switch aligned { @@ -607,7 +589,7 @@ public class Layout { /// Set the view's left coordinate right of the specified view. @discardableResult - public func right(of relativeView: UIView) -> Layout { + func right(of relativeView: UIView) -> PinLayout { func context() -> String { return "left(of: \(view))" } if let coordinate = computeCoordinates(forEdge: .right, of: relativeView, context: context) { setLeft(coordinate.x, context: context) @@ -616,7 +598,7 @@ public class Layout { } @discardableResult - public func right(of relativeView: UIView, aligned: VerticalAlignment) -> Layout { + func right(of relativeView: UIView, aligned: VerticalAlignment) -> PinLayout { func context() -> String { return "right(of: \(view), aligned: \(aligned))" } switch aligned { @@ -640,36 +622,36 @@ public class Layout { // width, height // @discardableResult - public func width(_ width: CGFloat) -> Layout { + func width(_ width: CGFloat) -> PinLayout { return setWidth(width, context: { return "width(\(width))" }) } @discardableResult - public func width(percent: CGFloat) -> Layout { + func width(percent: CGFloat) -> PinLayout { func context() -> String { return "width(percent: \(percent)%)" } guard let layoutSuperview = validateLayoutSuperview(context: context) else { return self } return setWidth(layoutSuperview.frame.width * percent / 100, context: context) } @discardableResult - public func width(of view: UIView) -> Layout { + func width(of view: UIView) -> PinLayout { return setWidth(view.frame.size.width, context: { return "width(of: \(view))" }) } @discardableResult - public func height(_ height: CGFloat) -> Layout { + func height(_ height: CGFloat) -> PinLayout { return setHeight(height, context: { return "height(\(height))" }) } @discardableResult - public func height(percent: CGFloat) -> Layout { + func height(percent: CGFloat) -> PinLayout { func context() -> String { return "height(percent: \(percent)%)" } guard let layoutSuperview = validateLayoutSuperview(context: context) else { return self } return setHeight(layoutSuperview.frame.height * percent / 100, context: context) } @discardableResult - public func height(of view: UIView) -> Layout { + func height(of view: UIView) -> PinLayout { return setHeight(view.frame.size.height, context: { return "height(of: \(view))" }) } @@ -677,7 +659,7 @@ public class Layout { // size, sizeToFit, sizeThatFits // @discardableResult - public func size(_ size: CGSize) -> Layout { + func size(_ size: CGSize) -> PinLayout { if isSizeNotSet(context: { return "size(CGSize(width: \(size.width), height: \(size.height)))" }) { width(size.width) height(size.height) @@ -686,7 +668,7 @@ public class Layout { } @discardableResult - public func size(of view: UIView) -> Layout { + func size(of view: UIView) -> PinLayout { func context() -> String { return "size(of \(view))" } let viewSize = view.frame.size @@ -698,7 +680,7 @@ public class Layout { } @discardableResult - public func sizeToFit() -> Layout { + func sizeToFit() -> PinLayout { shouldSizeToFit = true return self } @@ -707,7 +689,7 @@ public class Layout { // Margins // @discardableResult - public func margin(_ value: CGFloat) -> Layout { + func margin(_ value: CGFloat) -> PinLayout { marginTop = value marginLeft = value marginBottom = value @@ -716,39 +698,39 @@ public class Layout { } @discardableResult - public func marginHorizontal(_ value: CGFloat) -> Layout { + func marginHorizontal(_ value: CGFloat) -> PinLayout { marginLeft = value marginRight = value return self } @discardableResult - public func marginVertical(_ value: CGFloat) -> Layout { + func marginVertical(_ value: CGFloat) -> PinLayout { marginTop = value marginBottom = value return self } @discardableResult - public func marginTop(_ value: CGFloat) -> Layout { + func marginTop(_ value: CGFloat) -> PinLayout { marginTop = value return self } @discardableResult - public func marginLeft(_ value: CGFloat) -> Layout { + func marginLeft(_ value: CGFloat) -> PinLayout { marginLeft = value return self } @discardableResult - public func marginBottom(_ value: CGFloat) -> Layout { + func marginBottom(_ value: CGFloat) -> PinLayout { marginBottom = value return self } @discardableResult - public func marginRight(_ value: CGFloat) -> Layout { + func marginRight(_ value: CGFloat) -> PinLayout { marginRight = value return self } @@ -757,7 +739,7 @@ public class Layout { // Insets // @discardableResult - public func inset(_ value: CGFloat) -> Layout { + func inset(_ value: CGFloat) -> PinLayout { insetTop(value) insetLeft(value) insetBottom(value) @@ -766,38 +748,38 @@ public class Layout { } @discardableResult - public func insetTop(_ value: CGFloat) -> Layout { + func insetTop(_ value: CGFloat) -> PinLayout { insetTop = value return self } @discardableResult - public func insetLeft(_ value: CGFloat) -> Layout { + func insetLeft(_ value: CGFloat) -> PinLayout { insetLeft = value return self } @discardableResult - public func insetBottom(_ value: CGFloat) -> Layout { + func insetBottom(_ value: CGFloat) -> PinLayout { insetBottom = value return self } @discardableResult - public func insetRight(_ value: CGFloat) -> Layout { + func insetRight(_ value: CGFloat) -> PinLayout { insetRight = value return self } @discardableResult - public func insetHorizontal(_ value: CGFloat) -> Layout { + func insetHorizontal(_ value: CGFloat) -> PinLayout { insetLeft = value insetRight = value return self } @discardableResult - public func insetVertical(_ value: CGFloat) -> Layout { + func insetVertical(_ value: CGFloat) -> PinLayout { insetTop(value) insetBottom(value) return self @@ -807,7 +789,7 @@ public class Layout { // // MARK: Private methods // -extension Layout { +extension PinLayoutImpl { fileprivate func setTop(_ value: CGFloat, context: Context) { if bottom != nil && height != nil { warnConflict(context, ["bottom": bottom!, "height": height!]) @@ -881,70 +863,70 @@ extension Layout { } @discardableResult - fileprivate func setTopLeft(_ point: CGPoint, context: Context) -> Layout { + fileprivate func setTopLeft(_ point: CGPoint, context: Context) -> PinLayout { setLeft(point.x, context: context) setTop(point.y, context: context) return self } @discardableResult - fileprivate func setTopCenter(_ point: CGPoint, context: Context) -> Layout { + fileprivate func setTopCenter(_ point: CGPoint, context: Context) -> PinLayout { setHorizontalCenter(point.x, context: context) setTop(point.y, context: context) return self } @discardableResult - fileprivate func setTopRight(_ point: CGPoint, context: Context) -> Layout { + fileprivate func setTopRight(_ point: CGPoint, context: Context) -> PinLayout { setRight(point.x, context: context) setTop(point.y, context: context) return self } @discardableResult - fileprivate func setLeftCenter(_ point: CGPoint, context: Context) -> Layout { + fileprivate func setLeftCenter(_ point: CGPoint, context: Context) -> PinLayout { setLeft(point.x, context: context) setVerticalCenter(point.y, context: context) return self } @discardableResult - fileprivate func setCenter(_ point: CGPoint, context: Context) -> Layout { + fileprivate func setCenter(_ point: CGPoint, context: Context) -> PinLayout { setHorizontalCenter(point.x, context: context) setVerticalCenter(point.y, context: context) return self } @discardableResult - fileprivate func setRightCenter(_ point: CGPoint, context: Context) -> Layout { + fileprivate func setRightCenter(_ point: CGPoint, context: Context) -> PinLayout { setRight(point.x, context: context) setVerticalCenter(point.y, context: context) return self } @discardableResult - fileprivate func setBottomLeft(_ point: CGPoint, context: Context) -> Layout { + fileprivate func setBottomLeft(_ point: CGPoint, context: Context) -> PinLayout { setLeft(point.x, context: context) setBottom(point.y, context: context) return self } @discardableResult - fileprivate func setBottomCenter(_ point: CGPoint, context: Context) -> Layout { + fileprivate func setBottomCenter(_ point: CGPoint, context: Context) -> PinLayout { setHorizontalCenter(point.x, context: context) setBottom(point.y, context: context) return self } @discardableResult - fileprivate func setBottomRight(_ point: CGPoint, context: Context) -> Layout { + fileprivate func setBottomRight(_ point: CGPoint, context: Context) -> PinLayout { setRight(point.x, context: context) setBottom(point.y, context: context) return self } @discardableResult - fileprivate func setWidth(_ value: CGFloat, context: Context) -> Layout { + fileprivate func setWidth(_ value: CGFloat, context: Context) -> PinLayout { guard value >= 0 else { warn("The width (\(value)) must be greater or equal to 0.", context: context); return self } @@ -960,7 +942,7 @@ extension Layout { } @discardableResult - fileprivate func setHeight(_ value: CGFloat, context: Context) -> Layout { + fileprivate func setHeight(_ value: CGFloat, context: Context) -> PinLayout { guard value >= 0 else { warn("The height (\(value)) must be greater or equal to 0.", context: context); return self } @@ -1026,7 +1008,7 @@ extension Layout { apply(onView: view) } - public func apply(onView view: UIView) { + func apply(onView view: UIView) { // assert(width != nil && (right == nil || left == nil), "width and right+left shouldn't be set simultaneously") // assert(height != nil || (top == nil || bottom == nil), "height and top+bottom shouldn't be set simultaneously") // assert(hCenter == nil || (left == nil && right == nil), "hCenter and right+left shouldn't be set simultaneously") @@ -1172,21 +1154,22 @@ extension Layout { } fileprivate func warn(_ text: String, context: Context) { - guard Layout.logConflicts else { return } + guard PinLayoutImpl.logConflicts else { return } print("\nšŸ‘‰ Layout Warning: \(context()). \(text)\n") } fileprivate func warnPropertyAlreadySet(_ propertyName: String, propertyValue: CGFloat, context: Context) { - guard Layout.logConflicts else { return } + guard PinLayoutImpl.logConflicts else { return } print("\nšŸ‘‰ Layout Conflict: \(context()) won't be applied since it value has already been set to \(propertyValue).\n") } fileprivate func warnPropertyAlreadySet(_ propertyName: String, propertyValue: CGSize, context: Context) { + guard PinLayoutImpl.logConflicts else { return } print("\nšŸ‘‰ Layout Conflict: \(context()) won't be applied since it value has already been set to CGSize(width: \(propertyValue.width), height: \(propertyValue.height)).\n") } fileprivate func warnConflict(_ context: Context, _ properties: [String: CGFloat]) { - guard Layout.logConflicts else { return } + guard PinLayoutImpl.logConflicts else { return } var warning = "\nšŸ‘‰ Layout Conflict: \(context()) won't be applied since it conflicts with the following already set properties:\n" properties.forEach { (key, value) in warning += " \(key): \(value)\n" diff --git a/MCSwiftLayout/Types.swift b/MCSwiftLayout/Types.swift index 273f3319..c87e51be 100644 --- a/MCSwiftLayout/Types.swift +++ b/MCSwiftLayout/Types.swift @@ -8,6 +8,9 @@ import Foundation +typealias Context = () -> String +typealias Size = (width: CGFloat?, height: CGFloat?) + public class EdgeList { internal let view: UIView @@ -102,8 +105,8 @@ enum PinType: String { } public class Pin { - internal let view: UIView - internal let pinType: PinType + let view: UIView + let pinType: PinType /* var x: CGFloat { return point.x @@ -127,7 +130,7 @@ public class Pin { } }*/ - fileprivate init(view: UIView, pinType: PinType) { + init(view: UIView, pinType: PinType) { self.view = view self.pinType = pinType } diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Common/BasicView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Common/BasicView.swift index f287eb27..eb048fc0 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Common/BasicView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Common/BasicView.swift @@ -31,7 +31,7 @@ class BasicView: UIView { override func layoutSubviews() { super.layoutSubviews() - label.layout.top(0).left(0) + label.pin.top(0).left(0) } var sizeThatFitsExpectedArea: CGFloat = 40 * 40 diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Main/MenuView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Main/MenuView.swift index 90b603cb..b0b8e0ec 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Main/MenuView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Main/MenuView.swift @@ -35,7 +35,7 @@ class MenuView: UIView { override func layoutSubviews() { super.layoutSubviews() - tableView.layout.size(size) + tableView.pin.size(size) } } diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Main/MenuViewController.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Main/MenuViewController.swift index 6032af70..31cfbd01 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Main/MenuViewController.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Main/MenuViewController.swift @@ -80,7 +80,7 @@ class MenuViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(true) -// didSelect(page: .bothEdgesSnapped) + didSelect(page: .bothEdgesSnapped) } } diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/BothEdgesSnapped/BothEdgesSnappedView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/BothEdgesSnapped/BothEdgesSnappedView.swift index 2df74df7..7d902992 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/BothEdgesSnapped/BothEdgesSnappedView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/BothEdgesSnapped/BothEdgesSnappedView.swift @@ -96,7 +96,7 @@ class BothEdgesSnappedView: UIView { } // fileprivate func addView(_ view: BasicView) { -// view.layout.height(30).width(70) +// view.pin.height(30).width(70) // contentScrollView.addSubview(view) // } @@ -114,85 +114,85 @@ class BothEdgesSnappedView: UIView { aViewChild.frame = CGRect(x: 45, y: 50, width: 80, height: 80) bView.frame = CGRect(x: 160, y: 200, width: 40, height: 40) -// bView.layout.above(of: aView, aligned: .left) +// bView.pin.above(of: aView, aligned: .left) // expect(bView.frame).to(equal(CGRect(x: 100.0, y: 60.0, width: 40.0, height: 40.0))) -// bView.layout.above(of: aViewChild, aligned: .left) +// bView.pin.above(of: aViewChild, aligned: .left) // expect(bView.frame).to(equal(CGRect(x: 145.0, y: 110.0, width: 40.0, height: 40.0))) -// bView.layout.above(of: aView, aligned: .center) +// bView.pin.above(of: aView, aligned: .center) // expect(bView.frame).to(equal(CGRect(x: 180.0, y: 60.0, width: 40.0, height: 40.0))) -// bView.layout.above(of: aViewChild, aligned: .center) +// bView.pin.above(of: aViewChild, aligned: .center) // expect(bView.frame).to(equal(CGRect(x: 165.0, y: 110.0, width: 40.0, height: 40.0))) -// bView.layout.above(of: aView, aligned: .right) +// bView.pin.above(of: aView, aligned: .right) // expect(bView.frame).to(equal(CGRect(x: 260.0, y: 60.0, width: 40.0, height: 40.0))) -// bView.layout.above(of: aViewChild, aligned: .right) +// bView.pin.above(of: aViewChild, aligned: .right) // expect(bView.frame).to(equal(CGRect(x: 185.0, y: 110.0, width: 40.0, height: 40.0))) -// bView.layout.right(of: aView, aligned: .top) +// bView.pin.right(of: aView, aligned: .top) // expect(bView.frame).to(equal(CGRect(x: 300.0, y: 100.0, width: 40.0, height: 40.0))) -// bView.layout.right(of: aViewChild, aligned: .top) +// bView.pin.right(of: aViewChild, aligned: .top) // expect(bView.frame).to(equal(CGRect(x: 225.0, y: 150.0, width: 40.0, height: 40.0))) -// bView.layout.right(of: aView, aligned: .center) +// bView.pin.right(of: aView, aligned: .center) // expect(bView.frame).to(equal(CGRect(x: 300.0, y: 160.0, width: 40.0, height: 40.0))) -// bView.layout.right(of: aViewChild, aligned: .center) +// bView.pin.right(of: aViewChild, aligned: .center) // expect(bView.frame).to(equal(CGRect(x: 225.0, y: 170.0, width: 40.0, height: 40.0))) -// bView.layout.right(of: aView, aligned: .bottom) +// bView.pin.right(of: aView, aligned: .bottom) // expect(bView.frame).to(equal(CGRect(x: 300.0, y: 220.0, width: 40.0, height: 40.0))) -// bView.layout.right(of: aViewChild, aligned: .bottom) +// bView.pin.right(of: aViewChild, aligned: .bottom) // expect(bView.frame).to(equal(CGRect(x: 225.0, y: 190.0, width: 40.0, height: 40.0))) -// bView.layout.below(of: aView, aligned: .left) +// bView.pin.below(of: aView, aligned: .left) // expect(bView.frame).to(equal(CGRect(x: 100.0, y: 260.0, width: 40.0, height: 40.0))) -// bView.layout.below(of: aViewChild, aligned: .left) +// bView.pin.below(of: aViewChild, aligned: .left) // expect(bView.frame).to(equal(CGRect(x: 145.0, y: 230.0, width: 40.0, height: 40.0))) -// bView.layout.below(of: aView, aligned: .center) +// bView.pin.below(of: aView, aligned: .center) // expect(bView.frame).to(equal(CGRect(x: 180.0, y: 260.0, width: 40.0, height: 40.0))) -// bView.layout.below(of: aViewChild, aligned: .center) +// bView.pin.below(of: aViewChild, aligned: .center) // expect(bView.frame).to(equal(CGRect(x: 165.0, y: 230.0, width: 40.0, height: 40.0))) -// bView.layout.below(of: aView, aligned: .right) +// bView.pin.below(of: aView, aligned: .right) // expect(bView.frame).to(equal(CGRect(x: 260.0, y: 260.0, width: 40.0, height: 40.0))) -// bView.layout.below(of: aViewChild, aligned: .right) +// bView.pin.below(of: aViewChild, aligned: .right) // expect(bView.frame).to(equal(CGRect(x: 185.0, y: 230.0, width: 40.0, height: 40.0))) -// bView.layout.left(of: aView, aligned: .top) +// bView.pin.left(of: aView, aligned: .top) // expect(bView.frame).to(equal(CGRect(x: 60.0, y: 100.0, width: 40.0, height: 40.0))) -// bView.layout.left(of: aViewChild, aligned: .top) +// bView.pin.left(of: aViewChild, aligned: .top) // expect(bView.frame).to(equal(CGRect(x: 105.0, y: 150.0, width: 40.0, height: 40.0))) -// bView.layout.left(of: aView, aligned: .center) +// bView.pin.left(of: aView, aligned: .center) // expect(bView.frame).to(equal(CGRect(x: 60.0, y: 160.0, width: 40.0, height: 40.0))) -// bView.layout.left(of: aViewChild, aligned: .center) +// bView.pin.left(of: aViewChild, aligned: .center) // expect(bView.frame).to(equal(CGRect(x: 105.0, y: 170.0, width: 40.0, height: 40.0))) -// bView.layout.left(of: aView, aligned: .bottom) +// bView.pin.left(of: aView, aligned: .bottom) // expect(bView.frame).to(equal(CGRect(x: 60.0, y: 220.0, width: 40.0, height: 40.0))) -// bView.layout.left(of: aViewChild, aligned: .bottom) +// bView.pin.left(of: aViewChild, aligned: .bottom) // expect(bView.frame).to(equal(CGRect(x: 105.0, y: 190.0, width: 40.0, height: 40.0))) -// bView.layout.above(of: aView) +// bView.pin.above(of: aView) // expect(bView.frame).to(equal(CGRect(x: 160.0, y: 60.0, width: 40.0, height: 40.0))) -// bView.layout.above(of: aViewChild) +// bView.pin.above(of: aViewChild) // expect(bView.frame).to(equal(CGRect(x: 160.0, y: 110.0, width: 40.0, height: 40.0))) -// bView.layout.left(of: aView) +// bView.pin.left(of: aView) // expect(bView.frame).to(equal(CGRect(x: 60.0, y: 200.0, width: 40.0, height: 40.0))) -// bView.layout.left(of: aViewChild) +// bView.pin.left(of: aViewChild) // expect(bView.frame).to(equal(CGRect(x: 105.0, y: 200.0, width: 40.0, height: 40.0))) -// bView.layout.below(of: aView) +// bView.pin.below(of: aView) // expect(bView.frame).to(equal(CGRect(x: 160.0, y: 260.0, width: 40.0, height: 40.0))) -// bView.layout.below(of: aViewChild) +// bView.pin.below(of: aViewChild) // expect(bView.frame).to(equal(CGRect(x: 160.0, y: 230.0, width: 40.0, height: 40.0))) -// bView.layout.right(of: aView) +// bView.pin.right(of: aView) // expect(bView.frame).to(equal(CGRect(x: 300.0, y: 200.0, width: 40.0, height: 40.0))) -// bView.layout.right(of: aViewChild) +// bView.pin.right(of: aViewChild) // expect(bView.frame).to(equal(CGRect(x: 225.0, y: 200.0, width: 40.0, height: 40.0))) // MARGINS @@ -228,22 +228,22 @@ class BothEdgesSnappedView: UIView { // // sizeToFit // -// aView.layout.width(100).sizeToFit() +// aView.pin.width(100).sizeToFit() // expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 16.0))) -// aView.layout.width(of: aViewChild).sizeToFit() +// aView.pin.width(of: aViewChild).sizeToFit() // expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 50.0, height: 32.0))) -// aView.layout.height(100).sizeToFit() +// aView.pin.height(100).sizeToFit() // expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 16.0, height: 100.0))) -// aView.layout.height(of: aViewChild).sizeToFit() +// aView.pin.height(of: aViewChild).sizeToFit() // expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 53.3333333333333, height: 30.0))) -// aView.layout.size(of: aViewChild).sizeToFit() +// aView.pin.size(of: aViewChild).sizeToFit() // expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 50.0, height: 32.0))) -// aView.layout.size(CGSize(width: 20, height: 100)).sizeToFit() +// aView.pin.size(CGSize(width: 20, height: 100)).sizeToFit() // expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 20.0, height: 80.0))) rootView.frame = CGRect(x: 0, y: 0, width: 400, height: 400) @@ -252,72 +252,72 @@ class BothEdgesSnappedView: UIView { bView.frame = CGRect(x: 160, y: 200, width: 110, height: 80) bViewChild.frame = CGRect(x: 40, y: 10, width: 60, height: 20) -// aViewChild.layout.pinCenter(.center, of: aView).height(40).sizeToFit() +// aViewChild.pin.center(.center, of: aView).height(40).sizeToFit() // expect(aViewChild.frame).to(equal(CGRect(x: 30.0, y: 10.0, width: 40.0, height: 40.0))) // SHOULD EQUAL THESE 2 LINES: -// aViewChild.layout.width(40).height(40) -// aViewChild.layout.pinCenter(to: aView) +// aViewChild.pin.width(40).height(40) +// aViewChild.pin.center(to: aView) // expect(aViewChild.frame).to(equal(CGRect(x: 30.0, y: 10.0, width: 40.0, height: 40.0))) - aViewChild.layout.pinCenter(to: aView.pin.center).width(20).sizeToFit() + aViewChild.pin.center(to: aView.anchor.center).width(20).sizeToFit() // expect(aViewChild.frame).to(equal(CGRect(x: 40.0, y: -10.0, width: 20.0, height: 80.0))) // SHOULD EQUAL THESE 2 LINES: - //aViewChild.layout.width(20).height(80) - //aViewChild.layout.pinCenter(to: aView) + //aViewChild.pin.width(20).height(80) + //aViewChild.pin.center(to: aView) //expect(aViewChild.frame).to(equal(CGRect(x: 40.0, y: -10.0, width: 20.0, height: 80.0))) -// aViewChild.layout.pinTopLeft(.topLeft, of: bView).height(40).sizeToFit() -// aViewChild.layout.pinTopLeft(.topLeft, of: aView).height(40).sizeToFit() -// bView.layout.pinTopLeft(.topLeft, of: aViewChild).height(40).sizeToFit() +// aViewChild.pin.topLeft.topLeft, of: bView).height(40).sizeToFit() +// aViewChild.pin.topLeft.topLeft, of: aView).height(40).sizeToFit() +// bView.pin.topLeft.topLeft, of: aViewChild).height(40).sizeToFit() -// aView.layout.sizeThatFits(size: CGSize(width: 100, height: CGFloat.greatestFiniteMagnitude)) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 16.0) -// aView.layout.sizeThatFits(width: 100) // CGRect(x: 140.0, y: 100.0, width: 100.0, height: 16.0) -// aView.layout.sizeThatFits(widthOf: aViewChild) //CGRect(x: 140.0, y: 100.0, width: 50.0, height: 32.0) +// aView.pin.sizeThatFits(size: CGSize(width: 100, height: CGFloat.greatestFiniteMagnitude)) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 16.0) +// aView.pin.sizeThatFits(width: 100) // CGRect(x: 140.0, y: 100.0, width: 100.0, height: 16.0) +// aView.pin.sizeThatFits(widthOf: aViewChild) //CGRect(x: 140.0, y: 100.0, width: 50.0, height: 32.0) -// aView.layout.sizeThatFits(size: CGSize(width: CGFloat.greatestFiniteMagnitude, height: 100)) //CGRect(x: 140.0, y: 100.0, width: 16.0, height: 100.0) -// aView.layout.sizeThatFits(height: 100) //CGRect(x: 140.0, y: 100.0, width: 16.0, height: 100.0) -// aView.layout.sizeThatFits(heightOf: aViewChild)// CGRect(x: 140.0, y: 100.0, width: 53.3333333333333, height: 30.0) +// aView.pin.sizeThatFits(size: CGSize(width: CGFloat.greatestFiniteMagnitude, height: 100)) //CGRect(x: 140.0, y: 100.0, width: 16.0, height: 100.0) +// aView.pin.sizeThatFits(height: 100) //CGRect(x: 140.0, y: 100.0, width: 16.0, height: 100.0) +// aView.pin.sizeThatFits(heightOf: aViewChild)// CGRect(x: 140.0, y: 100.0, width: 53.3333333333333, height: 30.0) -// aView.layout.sizeThatFits(sizeOf: aViewChild)//CGRect(x: 140.0, y: 100.0, width: 50.0, height: 32.0) +// aView.pin.sizeThatFits(sizeOf: aViewChild)//CGRect(x: 140.0, y: 100.0, width: 50.0, height: 32.0) -// aView.layout.size(of: aViewChild)// CGRect(x: 140.0, y: 100.0, width: 50.0, height: 30.0) -// aView.layout.size(CGSize(width: 25, height: 25))//CGRect(x: 140.0, y: 100.0, width: 25.0, height: 25.0) +// aView.pin.size(of: aViewChild)// CGRect(x: 140.0, y: 100.0, width: 50.0, height: 30.0) +// aView.pin.size(CGSize(width: 25, height: 25))//CGRect(x: 140.0, y: 100.0, width: 25.0, height: 25.0) // // pin coordinate // -// aViewChild.layout.pinTop(.top, of: aView) //CGRect(x: 10.0, y: 0.0, width: 50.0, height: 30.0) -// aViewChild.layout.pinTop(.top, of: bView) // CGRect(x: 10.0, y: 100.0, width: 50.0, height: 30.0) - aViewChild.layout.pinTopLeft(to: bView.pin.bottomRight) -// bViewChild.layout.pinTop(.top, of: aViewChild) //CGRect(x: 40.0, y: -80.0, width: 60.0, height: 20.0) - -// aViewChild.layout.pinTop(.bottom, of: aView) //CGRect(x: 10.0, y: 60.0, width: 50.0, height: 30.0) -// aViewChild.layout.pinTop(.bottom, of: bView) //CGRect(x: 10.0, y: 180.0, width: 50.0, height: 30.0) -// bViewChild.layout.pinTop(.bottom, of: aViewChild) //CGRect(x: 40.0, y: -50.0, width: 60.0, height: 20.0) +// aViewChild.pin.top(.top, of: aView) //CGRect(x: 10.0, y: 0.0, width: 50.0, height: 30.0) +// aViewChild.pin.top(.top, of: bView) // CGRect(x: 10.0, y: 100.0, width: 50.0, height: 30.0) + aViewChild.pin.topLeft(to: bView.anchor.bottomRight) +// bViewChild.pin.top(.top, of: aViewChild) //CGRect(x: 40.0, y: -80.0, width: 60.0, height: 20.0) + +// aViewChild.pin.top(.bottom, of: aView) //CGRect(x: 10.0, y: 60.0, width: 50.0, height: 30.0) +// aViewChild.pin.top(.bottom, of: bView) //CGRect(x: 10.0, y: 180.0, width: 50.0, height: 30.0) +// bViewChild.pin.top(.bottom, of: aViewChild) //CGRect(x: 40.0, y: -50.0, width: 60.0, height: 20.0) -// aViewChild.layout.pinBottom(.top, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) -// aViewChild.layout.pinBottom(.top, of: bView) //CGRect(x: 10.0, y: 70.0, width: 50.0, height: 30.0) -// bViewChild.layout.pinBottom(.top, of: aViewChild) //CGRect(x: 40.0, y: -100.0, width: 60.0, height: 20.0) +// aViewChild.pin.bottom(.top, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) +// aViewChild.pin.bottom(.top, of: bView) //CGRect(x: 10.0, y: 70.0, width: 50.0, height: 30.0) +// bViewChild.pin.bottom(.top, of: aViewChild) //CGRect(x: 40.0, y: -100.0, width: 60.0, height: 20.0) // -// aViewChild.layout.pinBottom(.bottom, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) -// aViewChild.layout.pinBottom(.bottom, of: bView) //CGRect(x: 10.0, y: 150.0, width: 50.0, height: 30.0) -// bViewChild.layout.pinBottom(.bottom, of: aViewChild) //CGRect(x: 40.0, y: -70.0, width: 60.0, height: 20.0) +// aViewChild.pin.bottom(.bottom, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) +// aViewChild.pin.bottom(.bottom, of: bView) //CGRect(x: 10.0, y: 150.0, width: 50.0, height: 30.0) +// bViewChild.pin.bottom(.bottom, of: aViewChild) //CGRect(x: 40.0, y: -70.0, width: 60.0, height: 20.0) -// aViewChild.layout.pinLeft(.left, of: aView) //CGRect(x: 0.0, y: 20.0, width: 50.0, height: 30.0) -// aViewChild.layout.pinLeft(.left, of: bView) //CGRect(x: 20.0, y: 20.0, width: 50.0, height: 30.0) -// bViewChild.layout.pinLeft(.left, of: aViewChild) //CGRect(x: -10.0, y: 10.0, width: 60.0, height: 20.0) +// aViewChild.pin.left(.left, of: aView) //CGRect(x: 0.0, y: 20.0, width: 50.0, height: 30.0) +// aViewChild.pin.left(.left, of: bView) //CGRect(x: 20.0, y: 20.0, width: 50.0, height: 30.0) +// bViewChild.pin.left(.left, of: aViewChild) //CGRect(x: -10.0, y: 10.0, width: 60.0, height: 20.0) // -// aViewChild.layout.pinLeft(.right, of: aView) //CGRect(x: 100.0, y: 20.0, width: 50.0, height: 30.0) -// aViewChild.layout.pinLeft(.right, of: bView) //CGRect(x: 130.0, y: 20.0, width: 50.0, height: 30.0) -// bViewChild.layout.pinLeft(.right, of: aViewChild) //CGRect(x: 40.0, y: 10.0, width: 60.0, height: 20.0) +// aViewChild.pin.left(.right, of: aView) //CGRect(x: 100.0, y: 20.0, width: 50.0, height: 30.0) +// aViewChild.pin.left(.right, of: bView) //CGRect(x: 130.0, y: 20.0, width: 50.0, height: 30.0) +// bViewChild.pin.left(.right, of: aViewChild) //CGRect(x: 40.0, y: 10.0, width: 60.0, height: 20.0) -// aViewChild.layout.pinRight(.left, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) -// aViewChild.layout.pinRight(.left, of: bView) //CGRect(x: -30.0, y: 20.0, width: 50.0, height: 30.0) -// bViewChild.layout.pinRight(.left, of: aViewChild) //CGRect(x: -70.0, y: 10.0, width: 60.0, height: 20.0) +// aViewChild.pin.right(.left, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) +// aViewChild.pin.right(.left, of: bView) //CGRect(x: -30.0, y: 20.0, width: 50.0, height: 30.0) +// bViewChild.pin.right(.left, of: aViewChild) //CGRect(x: -70.0, y: 10.0, width: 60.0, height: 20.0) // -// aViewChild.layout.pinRight(.right, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) -// aViewChild.layout.pinRight(.right, of: bView) //CGRect(x: 80.0, y: 20.0, width: 50.0, height: 30.0) -// bViewChild.layout.pinRight(.right, of: aViewChild) //CGRect(x: -20.0, y: 10.0, width: 60.0, height: 20.0) +// aViewChild.pin.right(.right, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) +// aViewChild.pin.right(.right, of: bView) //CGRect(x: 80.0, y: 20.0, width: 50.0, height: 30.0) +// bViewChild.pin.right(.right, of: aViewChild) //CGRect(x: -20.0, y: 10.0, width: 60.0, height: 20.0) // // pin point @@ -329,77 +329,77 @@ class BothEdgesSnappedView: UIView { // bViewChild.frame = CGRect(x: 40, y: 10, width: 60, height: 20) // topLeft -// aView.layout.topLeft() // CGRect(x: 0.0, y: 0.0, width: 100.0, height: 60.0) -// aViewChild.layout.pinTopLeft(.topLeft, of: aView) //(of: aView) // CGRect(x: 0.0, y: 0.0, width: 50.0, height: 30.0) -// aViewChild.layout.pinTopLeft(of: aView) // CGRect(x: 0.0, y: 0.0, width: 50.0, height: 30.0) -// aViewChild.layout.pinTopLeft(of: aView).pinBottomRight() -// aViewChild.layout.topLeft(of: bView) // CGRect(x: 20.0, y: 100.0, width: 50.0, height: 30.0) -// bView.layout.topLeft(of: aViewChild) // CGRect(x: 150.0, y: 120.0, width: 110.0, height: 80.0) -// bViewChild.layout.pinTopLeft(to: aViewChild)< // CGRect(x: -10.0, y: -80.0, width: 60.0, height: 20.0) +// aView.pin.topLeft() // CGRect(x: 0.0, y: 0.0, width: 100.0, height: 60.0) +// aViewChild.pin.topLeft.topLeft, of: aView) //(of: aView) // CGRect(x: 0.0, y: 0.0, width: 50.0, height: 30.0) +// aViewChild.pin.topLeftof: aView) // CGRect(x: 0.0, y: 0.0, width: 50.0, height: 30.0) +// aViewChild.pin.topLeftof: aView).bottomRight() +// aViewChild.pin.topLeft(of: bView) // CGRect(x: 20.0, y: 100.0, width: 50.0, height: 30.0) +// bView.pin.topLeft(of: aViewChild) // CGRect(x: 150.0, y: 120.0, width: 110.0, height: 80.0) +// bViewChild.pin.topLeftto: aViewChild)< // CGRect(x: -10.0, y: -80.0, width: 60.0, height: 20.0) -// bView.layout.pinBottomRight().pinTopLeft(to: .zero).below(of: bViewChild) +// bView.pin.bottomRight().topLeftto: .zero).below(of: bViewChild) - // pinTopCenter -// aView.layout.pinTopCenter() // CGRect(x: 150.0, y: 0.0, width: 100.0, height: 60.0) -// aViewChild.layout.pinTopCenter(to: aView) //CGRect(x: 25.0, y: 0.0, width: 50.0, height: 30.0) -// aViewChild.layout.pinTopCenter(to: bView) //CGRect(x: 50.0, y: 100.0, width: 50.0, height: 30.0) -// bView.layout.pinTopCenter(to: aViewChild) //CGRect(x: 120.0, y: 120.0, width: 110.0, height: 80.0) -// bViewChild.layout.pinTopCenter(to: aViewChild) //CGRect(x: -15.0, y: -80.0, width: 60.0, height: 20.0) + // topCenter +// aView.pin..topCenter.() // CGRect(x: 150.0, y: 0.0, width: 100.0, height: 60.0) +// aViewChild.pin.topCenter(to: aView) //CGRect(x: 25.0, y: 0.0, width: 50.0, height: 30.0) +// aViewChild.pin.topCenter(to: bView) //CGRect(x: 50.0, y: 100.0, width: 50.0, height: 30.0) +// bView.pin.topCenter(to: aViewChild) //CGRect(x: 120.0, y: 120.0, width: 110.0, height: 80.0) +// bViewChild.pin.topCenter(to: aViewChild) //CGRect(x: -15.0, y: -80.0, width: 60.0, height: 20.0) - // pinTopRight -// aView.layout.pinTopRight() -// aViewChild.layout.pinTopRight(to: aView) -// aViewChild.layout.pinTopRight(to: bView) -// bView.layout.pinTopRight(to: aViewChild) -// bViewChild.layout.pinTopRight(to: aViewChild) + // topRight +// aView.pin.topRight() +// aViewChild.pin.topRight(to: aView) +// aViewChild.pin.topRight(to: bView) +// bView.pin.topRight(to: aViewChild) +// bViewChild.pin.topRight(to: aViewChild) - // pinLeftCenter -// aView.layout.pinLeftCenter() + // leftCenter +// aView.pin.leftCenter() // expect(aView.frame).to(equal(CGRect(x: 0.0, y: 170.0, width: 100.0, height: 60.0))) -// aViewChild.layout.pinLeftCenter(to: aView) +// aViewChild.pin.leftCenter(to: aView) // expect(aViewChild.frame).to(equal(CGRect(x: 0.0, y: 15.0, width: 50.0, height: 30.0))) -// aViewChild.layout.pinLeftCenter(to: bView) +// aViewChild.pin.leftCenter(to: bView) // expect(aViewChild.frame).to(equal(CGRect(x: 20.0, y: 125.0, width: 50.0, height: 30.0))) -// bView.layout.pinLeftCenter(to: aViewChild) +// bView.pin.leftCenter(to: aViewChild) // expect(bView.frame).to(equal(CGRect(x: 150.0, y: 95.0, width: 110.0, height: 80.0))) -// bViewChild.layout.pinLeftCenter(to: aViewChild) +// bViewChild.pin.leftCenter(to: aViewChild) // expect(bViewChild.frame).to(equal(CGRect(x: -10.0, y: -75.0, width: 60.0, height: 20.0))) - // pinCenter -// aView.layout.pinCenter() -// aViewChild.layout.pinCenter(to: aView) -// aViewChild.layout.pinCenter(to: bView) -// bView.layout.pinCenter(to: aViewChild) -// bViewChild.layout.pinCenter(to: aViewChild) + // center +// aView.pin.center() +// aViewChild.pin.center(to: aView) +// aViewChild.pin.center(to: bView) +// bView.pin.center(to: aViewChild) +// bViewChild.pin.center(to: aViewChild) - // pinRightCenter -// aView.layout.pinRightCenter() -// aViewChild.layout.pinRightCenter(to: aView) -// aViewChild.layout.pinRightCenter(to: bView) -// bView.layout.pinRightCenter(to: aViewChild) -// bViewChild.layout.pinRightCenter(to: aViewChild) - - // pinBottomLeft -// aView.layout.pinBottomLeft() -// aViewChild.layout.pinBottomLeft(to: aView) -// aViewChild.layout.pinBottomLeft(to: bView) -// bView.layout.pinBottomLeft(to: aViewChild) -// bViewChild.layout.pinBottomLeft(to: aViewChild) - - // pinBottomCenter -// aView.layout.pinBottomCenter() -// aViewChild.layout.pinBottomCenter(to: aView) -// aViewChild.layout.pinBottomCenter(to: bView) -// bView.layout.pinBottomCenter(to: aViewChild) -// bViewChild.layout.pinBottomCenter(to: aViewChild) - - // pinBottomRight -// aView.layout.pinBottomRight() -// aViewChild.layout.pinBottomRight(of: aView) -// aViewChild.layout.pinBottomRight(of: bView) -// bView.layout.pinBottomRight(of: aViewChild) -// bViewChild.layout.pinBottomRight(of: aViewChild) + // rightCenter +// aView.pin.rightCenter() +// aViewChild.pin.rightCenter(to: aView) +// aViewChild.pin.rightCenter(to: bView) +// bView.pin.rightCenter(to: aViewChild) +// bViewChild.pin.rightCenter(to: aViewChild) + + // bottomLeft +// aView.pin.bottomLeft() +// aViewChild.pin.bottomLeft(to: aView) +// aViewChild.pin.bottomLeft(to: bView) +// bView.pin.bottomLeft(to: aViewChild) +// bViewChild.pin.bottomLeft(to: aViewChild) + + // bottomCenter +// aView.pin.bottomCenter() +// aViewChild.pin.bottomCenter(to: aView) +// aViewChild.pin.bottomCenter(to: bView) +// bView.pin.bottomCenter(to: aViewChild) +// bViewChild.pin.bottomCenter(to: aViewChild) + + // bottomRight +// aView.pin.bottomRight() +// aViewChild.pin.bottomRight(of: aView) +// aViewChild.pin.bottomRight(of: bView) +// bView.pin.bottomRight(of: aViewChild) +// bViewChild.pin.bottomRight(of: aViewChild) printViewFrame(aView, name: "aView") printViewFrame(aViewChild, name: "aViewChild") diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ChainedLayoutView/ChainedLayoutView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ChainedLayoutView/ChainedLayoutView.swift index b52747d9..5b23cc3c 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ChainedLayoutView/ChainedLayoutView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ChainedLayoutView/ChainedLayoutView.swift @@ -53,7 +53,7 @@ class ChainedLayoutView: UIView { fileprivate func addSquare(_ view: UIView, color: UIColor) { view.backgroundColor = color - view.layout.height(50).width(50) + view.pin.height(50).width(50) addSubview(view) } @@ -64,7 +64,7 @@ class ChainedLayoutView: UIView { override func layoutSubviews() { super.layoutSubviews() - centerView.layout.width(200).height(200) + centerView.pin.width(200).height(200) centerView.center = CGPoint(x: 200, y: 300) print("topCenterView: \(topCenterView.frame)") @@ -74,15 +74,15 @@ class ChainedLayoutView: UIView { // topRightView.bottomRight = centerView.topRight //bottomLeftView.layout2.topLeft(centerView.bottomLeft).margins(10) -// bottomLeftView.layout.pinTopLeft(<#T##pin: Pin##Pin#>, of: <#T##UIView#>) +// bottomLeftView.pin.topLeft<#T##pin: Pin##Pin#>, of: <#T##UIView#>) // -// pinTopLeft(to: centerView.pin.bottomLeft).height(50).marginTop(10).marginBottom(10) -// bottomCenterView.layout.pinCenter(to: centerView.bottomCenter).height(50).marginTop(10).marginBottom(10) -// bottomRightView.layout.pinTopRight(to: centerView.bottomRight).height(50).marginTop(10).marginBottom(10) +// topLeft(to: centerView.pin.bottomLeft).height(50).marginTop(10).marginBottom(10) +// bottomCenterView.pin.center(to: centerView.bottomCenter).height(50).marginTop(10).marginBottom(10) +// bottomRightView.pin.topRight(to: centerView.bottomRight).height(50).marginTop(10).marginBottom(10) // -// rightTopView.layout.pinTopLeft(to: centerView.topRight).width(50).marginLeft(10).marginRight(10) -// rightCenterView.layout.pinLeftCenter(to: centerView.rightCenter).height(50).marginLeft(10).marginRight(10) -// rightBottomView.layout.pinBottomLeft(to: centerView.bottomRight).height(50).marginLeft(10).marginRight(10) +// rightTopView.pin.topLeftto: centerView.topRight).width(50).marginLeft(10).marginRight(10) +// rightCenterView.pin.leftCenter(to: centerView.rightCenter).height(50).marginLeft(10).marginRight(10) +// rightBottomView.pin.bottomLeft(to: centerView.bottomRight).height(50).marginLeft(10).marginRight(10) // // leftTopView.topRight = centerView.topLeft diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndInsets/MarginsAndInsetsView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndInsets/MarginsAndInsetsView.swift index 0551f207..42b3bf9e 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndInsets/MarginsAndInsetsView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndInsets/MarginsAndInsetsView.swift @@ -53,46 +53,46 @@ class MarginsAndInsetsView: UIView { rootView.frame = CGRect(x: 0, y: 0, width: 400, height: 400) aView.frame = CGRect(x: 140, y: 100, width: 200, height: 120) -// aView.layout.width(100).margin(10)//CGRect(x: 140.0, y: 100.0, width: 100.0, height: 120.0) -// aView.layout.width(100).inset(10)//CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.width(100).insetLeft(10)//CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0) -// aView.layout.width(100).insetLeft(10).insetRight(10)//CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.width(100).insetHorizontal(10)//CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.width(100).margins(10).insets(10)//CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.width(100).margin(10)//CGRect(x: 140.0, y: 100.0, width: 100.0, height: 120.0) +// aView.pin.width(100).inset(10)//CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.width(100).insetLeft(10)//CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0) +// aView.pin.width(100).insetLeft(10).insetRight(10)//CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.width(100).insetHorizontal(10)//CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.width(100).margins(10).insets(10)//CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.left(150).width(100).margin(10) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 120.0) -// aView.layout.left(140).width(100).inset(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.left(140).width(100).insetLeft(10) //CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0) -// aView.layout.left(140).width(100).insetRight(10) //CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0) -// aView.layout.left(140).width(100).insetLeft(10).insetRight(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.left(140).width(100).insetHorizontal(10)//CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.left(140).width(100).margin(10).inset(10)//CGRect(x: 160.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.left(140).width(100).marginLeft(10) //CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0) -// aView.layout.left(140).width(100).marginRight(10) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 120.0) -// aView.layout.left(140).width(100).marginHorizontal(10) //CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0) +// aView.pin.left(150).width(100).margin(10) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 120.0) +// aView.pin.left(140).width(100).inset(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.left(140).width(100).insetLeft(10) //CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0) +// aView.pin.left(140).width(100).insetRight(10) //CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0) +// aView.pin.left(140).width(100).insetLeft(10).insetRight(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.left(140).width(100).insetHorizontal(10)//CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.left(140).width(100).margin(10).inset(10)//CGRect(x: 160.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.left(140).width(100).marginLeft(10) //CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0) +// aView.pin.left(140).width(100).marginRight(10) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 120.0) +// aView.pin.left(140).width(100).marginHorizontal(10) //CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0) -// aView.layout.left(140).right(240).margin(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.left(140).right(240).inset(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.left(140).right(240).insetLeft(10) //CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0) -// aView.layout.left(140).right(240).insetRight(10) //CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0) -// aView.layout.left(140).right(240).insetLeft(10).insetRight(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.left(140).right(240).insetHorizontal(10)//CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.left(140).right(240).margin(10).inset(10)//CGRect(x: 160.0, y: 100.0, width: 60.0, height: 120.0) -// aView.layout.left(140).right(240).marginLeft(10) //CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0) -// aView.layout.left(140).right(240).marginRight(10) //CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0) -// aView.layout.left(140).right(240).marginLeft(10).marginRight(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.left(140).right(240).marginHorizontal(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.left(140).right(240).margin(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.left(140).right(240).inset(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.left(140).right(240).insetLeft(10) //CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0) +// aView.pin.left(140).right(240).insetRight(10) //CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0) +// aView.pin.left(140).right(240).insetLeft(10).insetRight(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.left(140).right(240).insetHorizontal(10)//CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.left(140).right(240).margin(10).inset(10)//CGRect(x: 160.0, y: 100.0, width: 60.0, height: 120.0) +// aView.pin.left(140).right(240).marginLeft(10) //CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0) +// aView.pin.left(140).right(240).marginRight(10) //CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0) +// aView.pin.left(140).right(240).marginLeft(10).marginRight(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.left(140).right(240).marginHorizontal(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.right(140).width(100).margin(10) //CGRect(x: 50.0, y: 100.0, width: 100.0, height: 120.0) -// aView.layout.right(140).width(100).inset(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.right(140).width(100).insetLeft(10) //CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0) -// aView.layout.right(140).width(100).insetRight(10) //CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0) -// aView.layout.right(140).width(100).insetLeft(10).insetRight(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.right(140).width(100).insetHorizontal(10)//CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.right(140).width(100).margin(10).inset(10)//CGRect(x: 160.0, y: 100.0, width: 80.0, height: 120.0) -// aView.layout.right(140).width(100).marginLeft(10) //CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0) -// aView.layout.right(140).width(100).marginRight(10) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 120.0) -// aView.layout.right(140).width(100).marginHorizontal(10) //CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0) +// aView.pin.right(140).width(100).margin(10) //CGRect(x: 50.0, y: 100.0, width: 100.0, height: 120.0) +// aView.pin.right(140).width(100).inset(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.right(140).width(100).insetLeft(10) //CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0) +// aView.pin.right(140).width(100).insetRight(10) //CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0) +// aView.pin.right(140).width(100).insetLeft(10).insetRight(10) //CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.right(140).width(100).insetHorizontal(10)//CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.right(140).width(100).margin(10).inset(10)//CGRect(x: 160.0, y: 100.0, width: 80.0, height: 120.0) +// aView.pin.right(140).width(100).marginLeft(10) //CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0) +// aView.pin.right(140).width(100).marginRight(10) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 120.0) +// aView.pin.right(140).width(100).marginHorizontal(10) //CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0) // TODO: Test top and bottom diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndPaddingsLeftRightView/MarginsAndPaddingsLeftRightView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndPaddingsLeftRightView/MarginsAndPaddingsLeftRightView.swift index 3e0ac04c..155f90d7 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndPaddingsLeftRightView/MarginsAndPaddingsLeftRightView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndPaddingsLeftRightView/MarginsAndPaddingsLeftRightView.swift @@ -81,7 +81,7 @@ class MarginsAndPaddingsLeftRightView: UIView { } fileprivate func addView(_ view: BasicView) { - view.layout.height(viewHeight).width(70) + view.pin.height(viewHeight).width(70) contentScrollView.addSubview(view) } @@ -94,82 +94,82 @@ class MarginsAndPaddingsLeftRightView: UIView { let leftPosition: CGFloat = 0 - contentScrollView.layout.pinTopLeft().width(width).height(height).insetTop(64) + contentScrollView.pin.topLeft().width(width).height(height).insetTop(64) descriptionLabel.size = descriptionLabel.sizeThatFits(CGSize(width: width, height: .greatestFiniteMagnitude)) - descriptionLabel.layout.pinTopLeft(to: CGPoint(x: leftPosition, y: 10)) + descriptionLabel.pin.topLeft(to: CGPoint(x: leftPosition, y: 10)) // No margins let rightPosition: CGFloat = 70 var topPosition = descriptionLabel.bottom + 10 - noMarginsNoPaddings.layout.top(topPosition).left(0).bottom(topPosition + viewHeight).right(rightPosition) + noMarginsNoPaddings.pin.top(topPosition).left(0).bottom(topPosition + viewHeight).right(rightPosition) expect(view: noMarginsNoPaddings, toMatchRect: CGRect(x: 0, y: 63, width: 70, height: 40)) topPosition += viewHeight - noMarginsLeftInsetView.layout.top(topPosition).left(0).bottom(topPosition + viewHeight).right(rightPosition).insetLeft(10) + noMarginsLeftInsetView.pin.top(topPosition).left(0).bottom(topPosition + viewHeight).right(rightPosition).insetLeft(10) expect(view: noMarginsLeftInsetView, toMatchRect: CGRect(x: 10, y: 103, width: 60, height: 40)) topPosition += viewHeight - noMarginsRightInsetView.layout.top(topPosition).left(0).bottom(topPosition + viewHeight).right(rightPosition).insetRight(10) + noMarginsRightInsetView.pin.top(topPosition).left(0).bottom(topPosition + viewHeight).right(rightPosition).insetRight(10) expect(view: noMarginsRightInsetView, toMatchRect: CGRect(x: 0, y: 143, width: 60, height: 40)) topPosition += viewHeight - noMarginsLeftRightInsetView.layout.top(topPosition).left(0).bottom(topPosition + viewHeight).right(rightPosition).insetLeft(10).insetRight(10) + noMarginsLeftRightInsetView.pin.top(topPosition).left(0).bottom(topPosition + viewHeight).right(rightPosition).insetLeft(10).insetRight(10) expect(view: noMarginsLeftRightInsetView, toMatchRect: CGRect(x: 10, y: 183, width: 50, height: 40)) topPosition += viewHeight // Left margin topPosition += 5 - leftMarginView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10) + leftMarginView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10) expect(view: leftMarginView, toMatchRect: CGRect(x: 10, y: 228, width: 60, height: 40)) topPosition += viewHeight - leftMarginLeftInsetView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).insetLeft(10) + leftMarginLeftInsetView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).insetLeft(10) expect(view: leftMarginLeftInsetView, toMatchRect: CGRect(x: 20, y: 268, width: 50, height: 40)) topPosition += viewHeight - leftMarginRightInsetView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).insetRight(10) + leftMarginRightInsetView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).insetRight(10) expect(view: leftMarginRightInsetView, toMatchRect: CGRect(x: 10, y: 308, width: 50, height: 40)) topPosition += viewHeight - leftMarginLeftRightInsetView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).insetLeft(10).insetRight(10) + leftMarginLeftRightInsetView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).insetLeft(10).insetRight(10) expect(view: leftMarginLeftRightInsetView, toMatchRect: CGRect(x: 20, y: 348, width: 40, height: 40)) topPosition += viewHeight // Right margin topPosition += 5 - rigthMarginView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginRight(10) + rigthMarginView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginRight(10) expect(view: rigthMarginView, toMatchRect: CGRect(x: 0, y: 393, width: 60, height: 40)) topPosition += viewHeight - rigthMarginLeftInsetView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginRight(10).insetLeft(10) + rigthMarginLeftInsetView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginRight(10).insetLeft(10) expect(view: rigthMarginLeftInsetView, toMatchRect: CGRect(x: 10, y: 433, width: 50, height: 40)) topPosition += viewHeight - rigthMarginRightInsetView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginRight(10).insetRight(10) + rigthMarginRightInsetView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginRight(10).insetRight(10) expect(view: rigthMarginRightInsetView, toMatchRect: CGRect(x: 0, y: 473, width: 50, height: 40)) topPosition += viewHeight - rigthMarginLeftRightInsetView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginRight(10).insetLeft(10).insetRight(10) + rigthMarginLeftRightInsetView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginRight(10).insetLeft(10).insetRight(10) expect(view: rigthMarginLeftRightInsetView, toMatchRect: CGRect(x: 10, y: 513, width: 40, height: 40)) topPosition += viewHeight // Left and right margins topPosition += 5 - leftRightMarginsView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).marginRight(10) + leftRightMarginsView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).marginRight(10) expect(view: leftRightMarginsView, toMatchRect: CGRect(x: 10, y: 558, width: 50, height: 40)) topPosition += viewHeight - leftRightMarginsLeftInsetView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).marginRight(10).insetLeft(10) + leftRightMarginsLeftInsetView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).marginRight(10).insetLeft(10) expect(view: leftRightMarginsLeftInsetView, toMatchRect: CGRect(x: 20, y: 598, width: 40, height: 40)) topPosition += viewHeight - leftRightMarginsRightInsetView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).marginRight(10).insetRight(10) + leftRightMarginsRightInsetView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).marginRight(10).insetRight(10) expect(view: leftRightMarginsRightInsetView, toMatchRect: CGRect(x: 10, y: 638, width: 40, height: 40)) topPosition += viewHeight - leftRightMarginsLeftRightInsetView.layout.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).marginRight(10).insetLeft(10).insetRight(10) + leftRightMarginsLeftRightInsetView.pin.top(topPosition).left(leftPosition).bottom(topPosition + viewHeight).right(rightPosition).marginLeft(10).marginRight(10).insetLeft(10).insetRight(10) expect(view: leftRightMarginsLeftRightInsetView, toMatchRect: CGRect(x: 20, y: 678, width: 30, height: 40)) topPosition += viewHeight diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndPaddingsLeftWidthView/MarginsAndPaddingsLeftWidthView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndPaddingsLeftWidthView/MarginsAndPaddingsLeftWidthView.swift index 4a5ae7d1..4c465807 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndPaddingsLeftWidthView/MarginsAndPaddingsLeftWidthView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MarginsAndPaddingsLeftWidthView/MarginsAndPaddingsLeftWidthView.swift @@ -90,7 +90,7 @@ class MarginsAndPaddingsLeftWidthView: UIView { } fileprivate func addView(_ view: BasicView) { - view.layout.height(30).width(70) + view.pin.height(30).width(70) contentScrollView.addSubview(view) } @@ -103,34 +103,34 @@ class MarginsAndPaddingsLeftWidthView: UIView { let leftPosition: CGFloat = 0 - contentScrollView.layout.pinTopLeft().width(width).height(height).insetTop(64) + contentScrollView.pin.topLeft().width(width).height(height).insetTop(64) descriptionLabel.size = descriptionLabel.sizeThatFits(CGSize(width: width, height: .greatestFiniteMagnitude)) - descriptionLabel.layout.pinTopLeft(to: CGPoint(x: leftPosition, y: 10)) + descriptionLabel.pin.topLeft(to: CGPoint(x: leftPosition, y: 10)) // No margins - noMarginsNoPaddings.layout.pinTopLeft(to: descriptionLabel.pin.bottomLeft).marginTop(5) - noMarginsLeftInsetView.layout.top(noMarginsNoPaddings.bottom).left(leftPosition).width(70).insetLeft(10) - noMarginsRightInsetView.layout.top(noMarginsLeftInsetView.bottom).left(leftPosition).width(70).insetRight(10) - noMarginsLeftRightInsetView.layout.top(noMarginsRightInsetView.bottom).left(leftPosition).width(70).insetLeft(10).insetRight(10) + noMarginsNoPaddings.pin.topLeft(to: descriptionLabel.anchor.bottomLeft).marginTop(5) + noMarginsLeftInsetView.pin.top(noMarginsNoPaddings.bottom).left(leftPosition).width(70).insetLeft(10) + noMarginsRightInsetView.pin.top(noMarginsLeftInsetView.bottom).left(leftPosition).width(70).insetRight(10) + noMarginsLeftRightInsetView.pin.top(noMarginsRightInsetView.bottom).left(leftPosition).width(70).insetLeft(10).insetRight(10) // Left margin - leftMarginView.layout.top(noMarginsLeftRightInsetView.bottom + 5).left(leftPosition).width(70).marginLeft(10) - leftMarginLeftInsetView.layout.top(leftMarginView.bottom).left(leftPosition).width(70).marginLeft(10).insetLeft(10) - leftMarginRightInsetView.layout.top(leftMarginLeftInsetView.bottom).left(leftPosition).width(70).marginLeft(10).insetRight(10) - leftMarginLeftRightInsetView.layout.top(leftMarginRightInsetView.bottom).left(leftPosition).width(70).marginLeft(10).insetLeft(10).insetRight(10) + leftMarginView.pin.top(noMarginsLeftRightInsetView.bottom + 5).left(leftPosition).width(70).marginLeft(10) + leftMarginLeftInsetView.pin.top(leftMarginView.bottom).left(leftPosition).width(70).marginLeft(10).insetLeft(10) + leftMarginRightInsetView.pin.top(leftMarginLeftInsetView.bottom).left(leftPosition).width(70).marginLeft(10).insetRight(10) + leftMarginLeftRightInsetView.pin.top(leftMarginRightInsetView.bottom).left(leftPosition).width(70).marginLeft(10).insetLeft(10).insetRight(10) // Right margin - rigthMarginView.layout.top(leftMarginLeftRightInsetView.bottom + 5).left(leftPosition).width(70).marginRight(10) - rigthMarginLeftInsetView.layout.top(rigthMarginView.bottom).left(leftPosition).width(70).marginRight(10).insetLeft(10) - rigthMarginRightInsetView.layout.top(rigthMarginLeftInsetView.bottom).left(leftPosition).width(70).marginRight(10).insetRight(10) - rigthMarginLeftRightInsetView.layout.top(rigthMarginRightInsetView.bottom).left(leftPosition).width(70).marginRight(10).insetLeft(10).insetRight(10) + rigthMarginView.pin.top(leftMarginLeftRightInsetView.bottom + 5).left(leftPosition).width(70).marginRight(10) + rigthMarginLeftInsetView.pin.top(rigthMarginView.bottom).left(leftPosition).width(70).marginRight(10).insetLeft(10) + rigthMarginRightInsetView.pin.top(rigthMarginLeftInsetView.bottom).left(leftPosition).width(70).marginRight(10).insetRight(10) + rigthMarginLeftRightInsetView.pin.top(rigthMarginRightInsetView.bottom).left(leftPosition).width(70).marginRight(10).insetLeft(10).insetRight(10) // Left and right margins - leftRightMarginsView.layout.top(rigthMarginLeftRightInsetView.bottom + 5).left(leftPosition).width(70).marginLeft(10).marginRight(10) - leftRightMarginsLeftInsetView.layout.top(leftRightMarginsView.bottom).left(leftPosition).width(70).marginLeft(10).marginRight(10).insetLeft(10) - leftRightMarginsRightInsetView.layout.top(leftRightMarginsLeftInsetView.bottom).left(leftPosition).width(70).marginLeft(10).marginRight(10).insetRight(10) - leftRightMarginsLeftRightInsetView.layout.top(leftRightMarginsRightInsetView.bottom).left(leftPosition).width(70).marginLeft(10).marginRight(10).insetLeft(10).insetRight(10) + leftRightMarginsView.pin.top(rigthMarginLeftRightInsetView.bottom + 5).left(leftPosition).width(70).marginLeft(10).marginRight(10) + leftRightMarginsLeftInsetView.pin.top(leftRightMarginsView.bottom).left(leftPosition).width(70).marginLeft(10).marginRight(10).insetLeft(10) + leftRightMarginsRightInsetView.pin.top(leftRightMarginsLeftInsetView.bottom).left(leftPosition).width(70).marginLeft(10).marginRight(10).insetRight(10) + leftRightMarginsLeftRightInsetView.pin.top(leftRightMarginsRightInsetView.bottom).left(leftPosition).width(70).marginLeft(10).marginRight(10).insetLeft(10).insetRight(10) // Top Margin // noMarginsNoPaddings2.layout2.top(leftRightMarginsLeftRightInsetView.bottom + 5).left(leftPosition).width(70).height(30) diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MultiRelativeView/MultiRelativeView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MultiRelativeView/MultiRelativeView.swift index 6cf4cf04..35fe88f2 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MultiRelativeView/MultiRelativeView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/MultiRelativeView/MultiRelativeView.swift @@ -32,9 +32,9 @@ class MultiRelativeView: UIView { override func layoutSubviews() { super.layoutSubviews() - view1.layout.top(64).left(10).width(100).height(100) - view2.layout.right(of: view1, aligned: .top).marginLeft(150).width(100).height(100) + view1.pin.top(64).left(10).width(100).height(100) + view2.pin.right(of: view1, aligned: .top).marginLeft(150).width(100).height(100) - view.layout.right(of: view1, aligned: .top).left(of: view2).height(75).insetLeft(10).insetRight(10) + view.pin.right(of: view1, aligned: .top).left(of: view2).height(75).insetLeft(10).insetRight(10) } } diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/PinScrolling/PinScrollingView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/PinScrolling/PinScrollingView.swift index dab1a7a3..365e64cf 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/PinScrolling/PinScrollingView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/PinScrolling/PinScrollingView.swift @@ -45,18 +45,18 @@ class PinScrollingView: UIView { override func layoutSubviews() { super.layoutSubviews() - contentScrollView.layout.pinTopLeft().width(width).height(height).insetTop(64) + contentScrollView.pin.topLeft().width(width).height(height).insetTop(64) contentScrollView.contentSize = CGSize(width: width, height: height * 4) - aView.layout.top(20).left(0).right(width).height(40).margin(10) + aView.pin.top(20).left(0).right(width).height(40).margin(10) layoutBView() - cView.layout.below(of: aView, aligned: .right).width(100).height(50).marginTop(10) - dView.layout.below(of: aView, aligned: .left).left(of: cView).height(of: cView).marginTop(10).marginRight(10) + cView.pin.below(of: aView, aligned: .right).width(100).height(50).marginTop(10) + dView.pin.below(of: aView, aligned: .left).left(of: cView).height(of: cView).marginTop(10).marginRight(10) } fileprivate func layoutBView() { - bView.layout.pinTopLeft(to: aView.pin.topLeft).pinBottomRight(to: aView.pin.bottomCenter) + bView.pin.topLeft(to: aView.anchor.topLeft).bottomRight(to: aView.anchor.bottomCenter) } } diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/RelativeView/RelativeView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/RelativeView/RelativeView.swift index 94a27e4b..3f4fb6ef 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/RelativeView/RelativeView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/RelativeView/RelativeView.swift @@ -62,7 +62,7 @@ class RelativeView: UIView { fileprivate func addSquare(_ view: UIView, color: UIColor) { view.backgroundColor = color - view.layout.width(50).height(50) + view.pin.width(50).height(50) addSubview(view) } @@ -73,7 +73,7 @@ class RelativeView: UIView { override func layoutSubviews() { super.layoutSubviews() - belowNavBarView.layout.pinTopLeft().size(size).insetTop(64) + belowNavBarView.pin.topLeft().size(size).insetTop(64) rootView.frame = CGRect(x: 20, y: 20, width: 400, height: 400) centerView.frame = CGRect(x: 100, y: 100, width: 200, height: 200) @@ -82,20 +82,20 @@ class RelativeView: UIView { // centerView.height = 200 // centerView.center = CGPoint(x: 200, y: 300) - topLeftView.layout.above(of: centerView, aligned: .left) - topCenterView.layout.above(of: centerView, aligned: .center) - topRightView.layout.above(of: centerView, aligned: .right) + topLeftView.pin.above(of: centerView, aligned: .left) + topCenterView.pin.above(of: centerView, aligned: .center) + topRightView.pin.above(of: centerView, aligned: .right) - leftTopView.layout.left(of: centerView, aligned: .top) - leftCenterView.layout.left(of: centerView, aligned: .center) - leftBottomView.layout.left(of: centerView, aligned: .bottom) + leftTopView.pin.left(of: centerView, aligned: .top) + leftCenterView.pin.left(of: centerView, aligned: .center) + leftBottomView.pin.left(of: centerView, aligned: .bottom) - bottomLeftView.layout.below(of: centerView, aligned: .left) - bottomCenterView.layout.below(of: centerView, aligned: .center) - bottomRightView.layout.below(of: centerView, aligned: .right) + bottomLeftView.pin.below(of: centerView, aligned: .left) + bottomCenterView.pin.below(of: centerView, aligned: .center) + bottomRightView.pin.below(of: centerView, aligned: .right) - rightTopView.layout.right(of: centerView, aligned: .top) - rightCenterView.layout.right(of: centerView, aligned: .center) - rightBottomView.layout.right(of: centerView, aligned: .bottom) + rightTopView.pin.right(of: centerView, aligned: .top) + rightCenterView.pin.right(of: centerView, aligned: .center) + rightBottomView.pin.right(of: centerView, aligned: .bottom) } } diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ValidateConflictsView/ValidateConflictsView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ValidateConflictsView/ValidateConflictsView.swift index 7d7604a2..8a4b6f11 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ValidateConflictsView/ValidateConflictsView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ValidateConflictsView/ValidateConflictsView.swift @@ -24,13 +24,13 @@ class ValidateConflictsView: UIView { fileprivate func addSquare(_ view: UIView, color: UIColor) { view.backgroundColor = color - view.layout.width(50).height(50) + view.pin.width(50).height(50) addSubview(view) } override func layoutSubviews() { super.layoutSubviews() - topLeftView.layout.right(10).width(20).top(10).left(10).left(10) + topLeftView.pin.right(10).width(20).top(10).left(10).left(10) } } diff --git a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ViewExtensionsPositionningView/ViewExtensionsPositionningView.swift b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ViewExtensionsPositionningView/ViewExtensionsPositionningView.swift index 796fa6c7..d05cb15f 100644 --- a/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ViewExtensionsPositionningView/ViewExtensionsPositionningView.swift +++ b/MCSwiftLayoutSample/MCSwiftLayoutSample/UI/Tests/ViewExtensionsPositionningView/ViewExtensionsPositionningView.swift @@ -53,7 +53,7 @@ class ViewExtensionsPositionningView: UIView { fileprivate func addSquare(_ view: UIView, color: UIColor) { view.backgroundColor = color - view.layout.width(50).height(50) + view.pin.width(50).height(50) addSubview(view) } @@ -64,7 +64,7 @@ class ViewExtensionsPositionningView: UIView { override func layoutSubviews() { super.layoutSubviews() - centerView.layout.width(200).height(200) + centerView.pin.width(200).height(200) centerView.center = CGPoint(x: 200, y: 300) print("topCenterView: \(topCenterView.frame)") diff --git a/MCSwiftLayoutTests/AdjustSizeSpec.swift b/MCSwiftLayoutTests/AdjustSizeSpec.swift index 25ae6db4..ba092f88 100644 --- a/MCSwiftLayoutTests/AdjustSizeSpec.swift +++ b/MCSwiftLayoutTests/AdjustSizeSpec.swift @@ -59,71 +59,71 @@ class AdjustSizeSpec: QuickSpec { describe("the result of the width(...) methods") { it("should ajust the width of aView") { - aView.layout.width(35) + aView.pin.width(35) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 35, height: 60.0))) } it("should not ajust the width of aView") { - aView.layout.width(-20) + aView.pin.width(-20) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100, height: 60.0))) } it("should ajust the width(percent: CGFloat) of aView") { - aView.layout.width(percent: 50) + aView.pin.width(percent: 50) expect(aView.frame).to(equal(CGRect(x: 140, y: 100, width: 200, height: 60))) } it("should ajust the width(percent: CGFloat) of aView") { - aView.layout.width(percent: 200) + aView.pin.width(percent: 200) expect(aView.frame).to(equal(CGRect(x: 140, y: 100, width: 800, height: 60))) } it("should not adjust the width(percent: CGFloat) of aView") { - aView.layout.width(percent: -20) + aView.pin.width(percent: -20) expect(aView.frame).to(equal(CGRect(x: 140, y: 100, width: 100, height: 60))) } it("should ajust the width(percent: CGFloat) of aView") { let unAttachedView = UIView(frame: CGRect(x: 10, y: 10, width: 20, height: 30)) - unAttachedView.layout.width(percent: 50) + unAttachedView.pin.width(percent: 50) expect(unAttachedView.frame).to(equal(CGRect(x: 10, y: 10, width: 20, height: 30))) } it("should ajust the width of aView") { - aView.layout.width(of: aViewChild) + aView.pin.width(of: aViewChild) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 50.0, height: 60.0))) } } describe("the result of the height(...) methods") { it("should ajust the height of aView") { - aView.layout.height(35) + aView.pin.height(35) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 35.0))) } it("should not ajust the height of aView") { - aView.layout.height(-20) + aView.pin.height(-20) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0))) } it("should ajust the width(percent: CGFloat) of aView") { - aView.layout.height(percent: 50) + aView.pin.height(percent: 50) expect(aView.frame).to(equal(CGRect(x: 140, y: 100, width: 100, height: 200))) } it("should ajust the width(percent: CGFloat) of aView") { - aView.layout.height(percent: 200) + aView.pin.height(percent: 200) expect(aView.frame).to(equal(CGRect(x: 140, y: 100, width: 100, height: 800))) } it("should ajust the width(percent: CGFloat) of aView") { let unAttachedView = UIView(frame: CGRect(x: 10, y: 10, width: 20, height: 30)) - unAttachedView.layout.height(percent: 50) + unAttachedView.pin.height(percent: 50) expect(unAttachedView.frame).to(equal(CGRect(x: 10, y: 10, width: 20, height: 30))) } it("should ajust the height of aView") { - aView.layout.height(of: aViewChild) + aView.pin.height(of: aViewChild) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 30.0))) } } @@ -131,22 +131,22 @@ class AdjustSizeSpec: QuickSpec { describe("the result of the size(...) methods") { it("should ajust the size of aView") { - aView.layout.size(CGSize(width: 25, height: 25)) + aView.pin.size(CGSize(width: 25, height: 25)) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 25.0, height: 25.0))) } it("should warn that size() won't be applied") { - aView.layout.width(90).size(CGSize(width: 25, height: 25)) + aView.pin.width(90).size(CGSize(width: 25, height: 25)) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 90.0, height: 60.0))) } it("should ajust the size of aView by calling a size(...) method") { - aView.layout.size(of: aViewChild) + aView.pin.size(of: aViewChild) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 50.0, height: 30.0))) } it("should warn that size(of) won't be applied") { - aView.layout.width(90).size(of: aViewChild) + aView.pin.width(90).size(of: aViewChild) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 90.0, height: 60.0))) } } @@ -156,49 +156,49 @@ class AdjustSizeSpec: QuickSpec { // describe("the result of the sizeToFit() method") { it("should ajust the size of aView by calling sizeToFit() method without having specified width and height") { - aView.layout.sizeToFit() + aView.pin.sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0))) } it("should ajust the size of aView by calling sizeToFit() method") { - aView.layout.width(100).sizeToFit() + aView.pin.width(100).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 16.0))) } it("should ajust the size of aView by calling sizeToFit() method") { - aView.layout.width(of: aViewChild).sizeToFit() + aView.pin.width(of: aViewChild).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 50.0, height: 32.0))) } it("should ajust the size of aView by calling sizeToFit() method") { - aView.layout.height(100).sizeToFit() + aView.pin.height(100).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 16.0, height: 100.0))) } it("should ajust the size of aView by calling sizeToFit() method") { - aView.layout.height(of: aViewChild).sizeToFit() + aView.pin.height(of: aViewChild).sizeToFit() expect(aView.frame).to(beCloseTo(CGRect(x: 140.0, y: 100.0, width: 53.3333333333333, height: 30.0), within: 0.3)) } it("should ajust the size of aView by calling sizeToFit() method") { - aView.layout.size(of: aViewChild).sizeToFit() + aView.pin.size(of: aViewChild).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 50.0, height: 30.0))) } it("should ajust the size of aView by calling sizeToFit() method") { - aView.layout.size(CGSize(width: 20, height: 100)).sizeToFit() + aView.pin.size(CGSize(width: 20, height: 100)).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 20.0, height: 80.0))) } - it("should ajust the size and position the view by calling pinCenter(), height() and sizeToFit()") { -// aViewChild.layout.pinCenter(.center, of: aView).height(40).sizeToFit() - aViewChild.layout.pinCenter(to: aView.pin.center).height(40).sizeToFit() + it("should ajust the size and position the view by calling center(), height() and sizeToFit()") { +// aViewChild.pin.center(.center, of: aView).height(40).sizeToFit() + aViewChild.pin.center(to: aView.anchor.center).height(40).sizeToFit() expect(aViewChild.frame).to(equal(CGRect(x: 30.0, y: 10.0, width: 40.0, height: 40.0))) } - it("should ajust the size and position the view by calling pinCenter(), width() and sizeToFit()") { -// aViewChild.layout.pinCenter(.center, of: aView).width(20).sizeToFit() - aViewChild.layout.pinCenter(to: aView.pin.center).width(20).sizeToFit() + it("should ajust the size and position the view by calling center(), width() and sizeToFit()") { +// aViewChild.pin.center(.center, of: aView).width(20).sizeToFit() + aViewChild.pin.center(to: aView.anchor.center).width(20).sizeToFit() expect(aViewChild.frame).to(equal(CGRect(x: 40.0, y: -10.0, width: 20.0, height: 80.0))) } } @@ -206,67 +206,67 @@ class AdjustSizeSpec: QuickSpec { describe("the result of the sizeThatFits(...) methods") { it("should ajust the size of aView by calling sizeThatFits(size: CGSize) method") { - aView.layout.width(100).sizeToFit() + aView.pin.width(100).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 16.0))) } it("should ajust the size of aView by calling sizeThatFits(size) method") { - aView.layout.height(100).sizeToFit() + aView.pin.height(100).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 16.0, height: 100.0))) } it("should warn that sizeThatFits(size:) won't be applied") { - aView.layout.top(0).bottom(70).width(100).sizeToFit() + aView.pin.top(0).bottom(70).width(100).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 0.0, width: 100.0, height: 70.0))) } it("should ajust the size of aView by calling sizeThatFits(width: CGFloat) method") { - aView.layout.width(100).sizeToFit() + aView.pin.width(100).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 16.0))) } it("should warn that sizeThatFits(width:) won't be applied") { - aView.layout.height(90).width(100).sizeToFit() + aView.pin.height(90).width(100).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 16.0))) } it("should ajust the size of aView by calling sizeThatFits(widthOf: UIView) method") { - aView.layout.width(of: aViewChild).sizeToFit() + aView.pin.width(of: aViewChild).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 50.0, height: 32.0))) } it("should warn that sizeThatFits(widthOf:) won't be applied") { - aView.layout.width(80).width(of: aViewChild).sizeToFit() + aView.pin.width(80).width(of: aViewChild).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 80.0, height: 20.0))) } it("should ajust the size of aView by calling sizeThatFits(height: CGFloat) method") { - aView.layout.height(100).sizeToFit() + aView.pin.height(100).sizeToFit() expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 16.0, height: 100.0))) } it("should warn that sizeThatFits(height:) won't be applied") { - aView.layout.width(90).height(100).sizeToFit() + aView.pin.width(90).height(100).sizeToFit() expect(aView.frame).to(beCloseTo(CGRect(x: 140.0, y: 100.0, width: 90.0, height: 17.6), within: 0.4)) } it("should ajust the size of aView by calling sizeThatFits(heightOf: UIView) method") { - aView.layout.height(of: aViewChild).sizeToFit() + aView.pin.height(of: aViewChild).sizeToFit() expect(aView.frame).to(beCloseTo(CGRect(x: 140.0, y: 100.0, width: 53.3333333333333, height: 30.0), within: 0.4)) } it("should warn that sizeThatFits(heightOf:) won't be applied") { - aView.layout.width(90).height(of: aViewChild).sizeToFit() + aView.pin.width(90).height(of: aViewChild).sizeToFit() expect(aView.frame).to(beCloseTo(CGRect(x: 140.0, y: 100.0, width: 90.0, height: 17.6), within: 0.4)) } it("should ajust the size of aView by calling sizeThatFits(sizeOf: UIView) method") { - aView.layout.size(of: aViewChild).sizeToFit() + aView.pin.size(of: aViewChild).sizeToFit() expect(aView.frame).to(beCloseTo(CGRect(x: 140.0, y: 100.0, width: 50.0, height: 30.0))) } it("should warn that sizeThatFits(sizeOf:) won't be applied") { - aView.layout.width(90).size(of: aViewChild).sizeToFit() + aView.pin.width(90).size(of: aViewChild).sizeToFit() expect(aView.frame).to(beCloseTo(CGRect(x: 140.0, y: 100.0, width: 90.0, height: 17.6), within: 0.4)) } } diff --git a/MCSwiftLayoutTests/BasicView.swift b/MCSwiftLayoutTests/BasicView.swift index f287eb27..eb048fc0 100644 --- a/MCSwiftLayoutTests/BasicView.swift +++ b/MCSwiftLayoutTests/BasicView.swift @@ -31,7 +31,7 @@ class BasicView: UIView { override func layoutSubviews() { super.layoutSubviews() - label.layout.top(0).left(0) + label.pin.top(0).left(0) } var sizeThatFitsExpectedArea: CGFloat = 40 * 40 diff --git a/MCSwiftLayoutTests/MCSwiftLayoutTests.swift b/MCSwiftLayoutTests/MCSwiftLayoutTests.swift index d63472ce..e1d76173 100644 --- a/MCSwiftLayoutTests/MCSwiftLayoutTests.swift +++ b/MCSwiftLayoutTests/MCSwiftLayoutTests.swift @@ -30,7 +30,7 @@ class MCSwiftLayoutTests: XCTestCase { // pin(rootView).topLeft(to: child1.pin.center) // rootView.pin.topLeft(to: child1.pin.center) -// child1.layout.pinCenter(of: rootView) +// child1.pin.pinCenter(of: rootView) // print("child1.frame: \(child1.frame)") } diff --git a/MCSwiftLayoutTests/MarginsAndInsetsSpec.swift b/MCSwiftLayoutTests/MarginsAndInsetsSpec.swift index 7313fd32..842729fd 100644 --- a/MCSwiftLayoutTests/MarginsAndInsetsSpec.swift +++ b/MCSwiftLayoutTests/MarginsAndInsetsSpec.swift @@ -41,193 +41,193 @@ class MarginsAndInsetsSpec: QuickSpec { // describe("the result of left&right margins and left&right insets when only the width is specified") { it("should adjust the aView") { - aView.layout.width(100).margin(10) + aView.pin.width(100).margin(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.width(100).inset(10) + aView.pin.width(100).inset(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.width(100).insetLeft(10) + aView.pin.width(100).insetLeft(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.width(100).insetLeft(10).insetRight(10) + aView.pin.width(100).insetLeft(10).insetRight(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.width(100).insetHorizontal(10) + aView.pin.width(100).insetHorizontal(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.width(100).margin(10).inset(10) + aView.pin.width(100).margin(10).inset(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 80.0, height: 120.0))) } } describe("the result of left&right margins and left&right insets when the left coordinate and the width are specified") { it("should adjust the aView") { - aView.layout.left(140).width(100).margin(10) + aView.pin.left(140).width(100).margin(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).width(100).inset(10) + aView.pin.left(140).width(100).inset(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).width(100).insetLeft(10) + aView.pin.left(140).width(100).insetLeft(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).width(100).insetRight(10) + aView.pin.left(140).width(100).insetRight(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).width(100).insetLeft(10).insetRight(10) + aView.pin.left(140).width(100).insetLeft(10).insetRight(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).width(100).insetHorizontal(10) + aView.pin.left(140).width(100).insetHorizontal(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).width(100).margin(10).inset(10) + aView.pin.left(140).width(100).margin(10).inset(10) expect(aView.frame).to(equal(CGRect(x: 160.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).width(100).marginLeft(10) + aView.pin.left(140).width(100).marginLeft(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).width(100).marginRight(10) + aView.pin.left(140).width(100).marginRight(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).width(100).marginHorizontal(10) + aView.pin.left(140).width(100).marginHorizontal(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 100.0, height: 120.0))) } } describe("the result of left&right margins and left&right insets when the right coordinate and the width are specified") { it("should adjust the aView") { - aView.layout.right(140).width(100).margin(10) + aView.pin.right(140).width(100).margin(10) expect(aView.frame).to(equal(CGRect(x: 30.0, y: 100.0, width: 100.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.right(140).width(100).inset(10) + aView.pin.right(140).width(100).inset(10) expect(aView.frame).to(equal(CGRect(x: 50.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.right(140).width(100).insetLeft(10) + aView.pin.right(140).width(100).insetLeft(10) expect(aView.frame).to(equal(CGRect(x: 50.0, y: 100.0, width: 90.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.right(140).width(100).margin(10).inset(10) + aView.pin.right(140).width(100).margin(10).inset(10) expect(aView.frame).to(equal(CGRect(x: 40.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.right(140).width(100).insetRight(10) + aView.pin.right(140).width(100).insetRight(10) expect(aView.frame).to(equal(CGRect(x: 40.0, y: 100.0, width: 90.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.right(140).width(100).insetLeft(10).insetRight(10) + aView.pin.right(140).width(100).insetLeft(10).insetRight(10) expect(aView.frame).to(equal(CGRect(x: 50.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.right(140).width(100).insetHorizontal(10) + aView.pin.right(140).width(100).insetHorizontal(10) expect(aView.frame).to(equal(CGRect(x: 50.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.right(140).width(100).marginLeft(10) + aView.pin.right(140).width(100).marginLeft(10) expect(aView.frame).to(equal(CGRect(x: 40.0, y: 100.0, width: 100.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.right(140).width(100).marginRight(10) + aView.pin.right(140).width(100).marginRight(10) expect(aView.frame).to(equal(CGRect(x: 30.0, y: 100.0, width: 100.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.right(140).width(100).marginHorizontal(10) + aView.pin.right(140).width(100).marginHorizontal(10) expect(aView.frame).to(equal(CGRect(x: 30.0, y: 100.0, width: 100.0, height: 120.0))) } } describe("the result of left&right margins and left&right insets when the left and right coordinate are specified") { it("should adjust the aView") { - aView.layout.left(140).right(240).margin(10) + aView.pin.left(140).right(240).margin(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).right(240).inset(10) + aView.pin.left(140).right(240).inset(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).right(240).insetLeft(10) + aView.pin.left(140).right(240).insetLeft(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).right(240).insetRight(10) + aView.pin.left(140).right(240).insetRight(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).right(240).insetLeft(10).insetRight(10) + aView.pin.left(140).right(240).insetLeft(10).insetRight(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).right(240).insetHorizontal(10) + aView.pin.left(140).right(240).insetHorizontal(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).right(240).margin(10).inset(10) + aView.pin.left(140).right(240).margin(10).inset(10) expect(aView.frame).to(equal(CGRect(x: 160.0, y: 100.0, width: 60.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).right(240).marginLeft(10) + aView.pin.left(140).right(240).marginLeft(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 90.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).right(240).marginRight(10) + aView.pin.left(140).right(240).marginRight(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 90.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).right(240).marginLeft(10).marginRight(10) + aView.pin.left(140).right(240).marginLeft(10).marginRight(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0))) } it("should adjust the aView") { - aView.layout.left(140).right(240).marginHorizontal(10) + aView.pin.left(140).right(240).marginHorizontal(10) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 100.0, width: 80.0, height: 120.0))) } } @@ -239,193 +239,193 @@ class MarginsAndInsetsSpec: QuickSpec { // TODO: DO top and bottom !!! duplicate everything above! describe("the result of top&bottom margins and top&bottom insets when only the height is specified") { it("should adjust the aView") { - aView.layout.height(100).margin(10) + aView.pin.height(100).margin(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 200.0, height: 100.0))) } it("should adjust the aView") { - aView.layout.height(100).inset(10) + aView.pin.height(100).inset(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.height(100).insetTop(10) + aView.pin.height(100).insetTop(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 200.0, height: 90))) } it("should adjust the aView") { - aView.layout.height(100).insetTop(10).insetBottom(10) + aView.pin.height(100).insetTop(10).insetBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.height(100).insetVertical(10) + aView.pin.height(100).insetVertical(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.height(100).margin(10).inset(10) + aView.pin.height(100).margin(10).inset(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 200.0, height: 80.0))) } } describe("the result of top&bottom margins and top&bottom insets when the top coordinate and the height are specified") { it("should adjust the aView") { - aView.layout.top(140).height(100).margin(10) + aView.pin.top(140).height(100).margin(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 100.0))) } it("should adjust the aView") { - aView.layout.top(140).height(100).inset(10) + aView.pin.top(140).height(100).inset(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.top(140).height(100).insetTop(10) + aView.pin.top(140).height(100).insetTop(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 90.0))) } it("should adjust the aView") { - aView.layout.top(140).height(100).insetBottom(10) + aView.pin.top(140).height(100).insetBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 140.0, width: 200.0, height: 90.0))) } it("should adjust the aView") { - aView.layout.top(140).height(100).insetTop(10).insetBottom(10) + aView.pin.top(140).height(100).insetTop(10).insetBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.top(140).height(100).insetVertical(10) + aView.pin.top(140).height(100).insetVertical(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.top(140).height(100).margin(10).inset(10) + aView.pin.top(140).height(100).margin(10).inset(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 160.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.top(140).height(100).marginTop(10) + aView.pin.top(140).height(100).marginTop(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 100.0))) } it("should adjust the aView") { - aView.layout.top(140).height(100).marginBottom(10) + aView.pin.top(140).height(100).marginBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 140.0, width: 200.0, height: 100.0))) } it("should adjust the aView") { - aView.layout.top(140).height(100).marginVertical(10) + aView.pin.top(140).height(100).marginVertical(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 100.0))) } } describe("the result of top&bottom margins and top&bottom insets when the bottom coordinate and the height are specified") { it("should adjust the aView") { - aView.layout.bottom(140).height(100).margin(10) + aView.pin.bottom(140).height(100).margin(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 30.0, width: 200.0, height: 100.0))) } it("should adjust the aView") { - aView.layout.bottom(140).height(100).inset(10) + aView.pin.bottom(140).height(100).inset(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 50.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.bottom(140).height(100).insetTop(10) + aView.pin.bottom(140).height(100).insetTop(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 50.0, width: 200.0, height: 90.0))) } it("should adjust the aView") { - aView.layout.bottom(140).height(100).margin(10).inset(10) + aView.pin.bottom(140).height(100).margin(10).inset(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 40.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.bottom(140).height(100).insetBottom(10) + aView.pin.bottom(140).height(100).insetBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 40.0, width: 200.0, height: 90.0))) } it("should adjust the aView") { - aView.layout.bottom(140).height(100).insetTop(10).insetBottom(10) + aView.pin.bottom(140).height(100).insetTop(10).insetBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 50.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.bottom(140).height(100).insetVertical(10) + aView.pin.bottom(140).height(100).insetVertical(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 50.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.bottom(140).height(100).marginTop(10) + aView.pin.bottom(140).height(100).marginTop(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 40.0, width: 200.0, height: 100.0))) } it("should adjust the aView") { - aView.layout.bottom(140).height(100).marginBottom(10) + aView.pin.bottom(140).height(100).marginBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 30.0, width: 200.0, height: 100.0))) } it("should adjust the aView") { - aView.layout.bottom(140).height(100).marginVertical(10) + aView.pin.bottom(140).height(100).marginVertical(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 30.0, width: 200.0, height: 100.0))) } } describe("the result of top&bottom margins and top&bottom insets when the top and bottom coordinate are specified") { it("should adjust the aView") { - aView.layout.top(140).bottom(240).margin(10) + aView.pin.top(140).bottom(240).margin(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.top(140).bottom(240).inset(10) + aView.pin.top(140).bottom(240).inset(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.top(140).bottom(240).insetTop(10) + aView.pin.top(140).bottom(240).insetTop(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 90.0))) } it("should adjust the aView") { - aView.layout.top(140).bottom(240).insetBottom(10) + aView.pin.top(140).bottom(240).insetBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 140.0, width: 200.0, height: 90.0))) } it("should adjust the aView") { - aView.layout.top(140).bottom(240).insetTop(10).insetBottom(10) + aView.pin.top(140).bottom(240).insetTop(10).insetBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.top(140).bottom(240).insetVertical(10) + aView.pin.top(140).bottom(240).insetVertical(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.top(140).bottom(240).margin(10).inset(10) + aView.pin.top(140).bottom(240).margin(10).inset(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 160.0, width: 200.0, height: 60.0))) } it("should adjust the aView") { - aView.layout.top(140).bottom(240).marginTop(10) + aView.pin.top(140).bottom(240).marginTop(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 90.0))) } it("should adjust the aView") { - aView.layout.top(140).bottom(240).marginBottom(10) + aView.pin.top(140).bottom(240).marginBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 140.0, width: 200.0, height: 90.0))) } it("should adjust the aView") { - aView.layout.top(140).bottom(240).marginTop(10).marginBottom(10) + aView.pin.top(140).bottom(240).marginTop(10).marginBottom(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 80.0))) } it("should adjust the aView") { - aView.layout.top(140).bottom(240).marginVertical(10) + aView.pin.top(140).bottom(240).marginVertical(10) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 150.0, width: 200.0, height: 80.0))) } } diff --git a/MCSwiftLayoutTests/PinEdgeCoordinateSpec.swift b/MCSwiftLayoutTests/PinEdgeCoordinateSpec.swift index ce522441..6d7f02ac 100644 --- a/MCSwiftLayoutTests/PinEdgeCoordinateSpec.swift +++ b/MCSwiftLayoutTests/PinEdgeCoordinateSpec.swift @@ -56,94 +56,94 @@ class PinEdgeCoordinateSpec: QuickSpec { bView.addSubview(bViewChild) } - describe("the result of the pinTop(edge: VerticalEdge, of: UIView) method") { + describe("the result of the top(edge: VerticalEdge, of: UIView) method") { it("should warns that the view is not added to any view") { let unAttachedView = UIView(frame: CGRect(x: 10, y: 10, width: 10, height: 10)) - unAttachedView.layout.pinTop(to: aView.edge.top) + unAttachedView.pin.top(to: aView.edge.top) expect(unAttachedView.frame).to(equal(CGRect(x: 10, y: 10, width: 10, height: 10))) } } // - // pinTop + // top // - describe("the result of the pinTop(edge: VerticalEdge, of: UIView)") { + describe("the result of the top(edge: VerticalEdge, of: UIView)") { it("should position the aViewChild's top edge on its parent's top edge") { - aViewChild.layout.pinTop(to: aView.edge.top) + aViewChild.pin.top(to: aView.edge.top) expect(aViewChild.frame).to(equal(CGRect(x: 10.0, y: 0.0, width: 50.0, height: 30.0))) } it("should position the aViewChild's top edge on its parent sibling (bView)'s top edge") { - aViewChild.layout.pinTop(to: bView.edge.top) + aViewChild.pin.top(to: bView.edge.top) expect(aViewChild.frame).to(equal(CGRect(x: 10.0, y: 100.0, width: 50.0, height: 30.0))) } it("should position the bViewChild's top edge on its sibling's children (aViewChild)'s top edge") { - bViewChild.layout.pinTop(to: aViewChild.edge.top) + bViewChild.pin.top(to: aViewChild.edge.top) expect(bViewChild.frame).to(equal(CGRect(x: 40.0, y: -80.0, width: 60.0, height: 20.0))) } it("should position the aViewChild's top edge on its parent's bottom edge") { - aViewChild.layout.pinTop(to: aView.edge.bottom) + aViewChild.pin.top(to: aView.edge.bottom) expect(aViewChild.frame).to(equal(CGRect(x: 10.0, y: 60.0, width: 50.0, height: 30.0))) } it("should position the aViewChild's top edge on its parent sibling (bView)'s bottom edge") { - aViewChild.layout.pinTop(to: bView.edge.bottom) + aViewChild.pin.top(to: bView.edge.bottom) expect(aViewChild.frame).to(equal(CGRect(x: 10.0, y: 180.0, width: 50.0, height: 30.0))) } it("should position the bViewChild's top edge on its sibling's children (aViewChild)'s bottom edge") { - bViewChild.layout.pinTop(to: aViewChild.edge.bottom) + bViewChild.pin.top(to: aViewChild.edge.bottom) expect(bViewChild.frame).to(equal(CGRect(x: 40.0, y: -50.0, width: 60.0, height: 20.0))) } } // - // pinLeft + // left // - describe("the result of the pinLeft(edge: VerticalEdge, of: UIView)") { + describe("the result of the left(edge: VerticalEdge, of: UIView)") { it("should position the aViewChild's left edge on its parent's left edge") { - aViewChild.layout.pinLeft(to: aView.edge.left) + aViewChild.pin.left(to: aView.edge.left) expect(aViewChild.frame).to(equal(CGRect(x: 0.0, y: 20.0, width: 50.0, height: 30.0))) } it("should position the aViewChild's left edge on its parent sibling (bView)'s left edge") { - aViewChild.layout.pinLeft(to: bView.edge.left) + aViewChild.pin.left(to: bView.edge.left) expect(aViewChild.frame).to(equal(CGRect(x: 20.0, y: 20.0, width: 50.0, height: 30.0))) } it("should position the bViewChild's left edge on its sibling's children (aViewChild)'s left edge") { - bViewChild.layout.pinLeft(to: aViewChild.edge.left) + bViewChild.pin.left(to: aViewChild.edge.left) expect(bViewChild.frame).to(equal(CGRect(x: -10.0, y: 10.0, width: 60.0, height: 20.0))) } it("should position the aViewChild's left edge on its parent's right edge") { - aViewChild.layout.pinLeft(to: aView.edge.right) + aViewChild.pin.left(to: aView.edge.right) expect(aViewChild.frame).to(equal(CGRect(x: 100.0, y: 20.0, width: 50.0, height: 30.0))) } it("should position the aViewChild's left edge on its parent sibling (bView)'s right edge") { - aViewChild.layout.pinLeft(to: bView.edge.right) + aViewChild.pin.left(to: bView.edge.right) expect(aViewChild.frame).to(equal(CGRect(x: 130.0, y: 20.0, width: 50.0, height: 30.0))) } it("should position the bViewChild's left edge on its sibling's children (aViewChild)'s right edge") { - bViewChild.layout.pinLeft(to: aViewChild.edge.right) + bViewChild.pin.left(to: aViewChild.edge.right) expect(bViewChild.frame).to(equal(CGRect(x: 40.0, y: 10.0, width: 60.0, height: 20.0))) } } // - // pinBottom + // bottom // - describe("the result of the pinBottom(edge: HorizontalEdge, of: UIView)") { + describe("the result of the bottom(edge: HorizontalEdge, of: UIView)") { it("should position the aViewChild's left edge on its parent's left edge") { -// aViewChild.layout.pinBottom(.top, of: aView) +// aViewChild.pin.bottom(.top, of: aView) // expect(aViewChild.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0))) } @@ -173,19 +173,19 @@ class PinEdgeCoordinateSpec: QuickSpec { } } // // - // aViewChild.layout.pinBottom(.top, of: bView) //CGRect(x: 10.0, y: 70.0, width: 50.0, height: 30.0) - // bViewChild.layout.pinBottom(.top, of: aViewChild) //CGRect(x: 40.0, y: -100.0, width: 60.0, height: 20.0) + // aViewChild.pin.bottom(.top, of: bView) //CGRect(x: 10.0, y: 70.0, width: 50.0, height: 30.0) + // bViewChild.pin.bottom(.top, of: aViewChild) //CGRect(x: 40.0, y: -100.0, width: 60.0, height: 20.0) // - // aViewChild.layout.pinBottom(.bottom, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) - // aViewChild.layout.pinBottom(.bottom, of: bView) //CGRect(x: 10.0, y: 150.0, width: 50.0, height: 30.0) - // bViewChild.layout.pinBottom(.bottom, of: aViewChild) //CGRect(x: 40.0, y: -70.0, width: 60.0, height: 20.0) + // aViewChild.pin.bottom(.bottom, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) + // aViewChild.pin.bottom(.bottom, of: bView) //CGRect(x: 10.0, y: 150.0, width: 50.0, height: 30.0) + // bViewChild.pin.bottom(.bottom, of: aViewChild) //CGRect(x: 40.0, y: -70.0, width: 60.0, height: 20.0) - // aViewChild.layout.pinRight(.left, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) - // aViewChild.layout.pinRight(.left, of: bView) //CGRect(x: -30.0, y: 20.0, width: 50.0, height: 30.0) - // bViewChild.layout.pinRight(.left, of: aViewChild) //CGRect(x: -70.0, y: 10.0, width: 60.0, height: 20.0) + // aViewChild.pin.right(.left, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) + // aViewChild.pin.right(.left, of: bView) //CGRect(x: -30.0, y: 20.0, width: 50.0, height: 30.0) + // bViewChild.pin.right(.left, of: aViewChild) //CGRect(x: -70.0, y: 10.0, width: 60.0, height: 20.0) // - // aViewChild.layout.pinRight(.right, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) - // aViewChild.layout.pinRight(.right, of: bView) //CGRect(x: 80.0, y: 20.0, width: 50.0, height: 30.0) - // bViewChild.layout.pinRight(.right, of: aViewChild) //CGRect(x: -20.0, y: 10.0, width: 60.0, height: 20.0) + // aViewChild.pin.right(.right, of: aView) //CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0) + // aViewChild.pin.right(.right, of: bView) //CGRect(x: 80.0, y: 20.0, width: 50.0, height: 30.0) + // bViewChild.pin.right(.right, of: aViewChild) //CGRect(x: -20.0, y: 10.0, width: 60.0, height: 20.0) } } diff --git a/MCSwiftLayoutTests/PinPointCoordinatesSpec.swift b/MCSwiftLayoutTests/PinPointCoordinatesSpec.swift index ec207014..aa3b1a04 100644 --- a/MCSwiftLayoutTests/PinPointCoordinatesSpec.swift +++ b/MCSwiftLayoutTests/PinPointCoordinatesSpec.swift @@ -59,7 +59,7 @@ class PinPointCoordinatesSpec: QuickSpec { describe("the result of the centers(to: UIView) method") { it("should warns that the view is not added to any view") { let unAttachedView = UIView(frame: CGRect(x: 10, y: 10, width: 10, height: 10)) - unAttachedView.layout.pinCenter(to: rootView.pin.bottomCenter) + unAttachedView.pin.center(to: rootView.anchor.bottomCenter) expect(unAttachedView.frame).to(equal(CGRect(x: 10, y: 10, width: 10, height: 10))) } @@ -71,36 +71,36 @@ class PinPointCoordinatesSpec: QuickSpec { describe("the result of the topLeft() and topLeft(to: UIView) methods") { it("should position the aView's topLeft corner at the specified position") { - aView.layout.pinTopLeft(to: CGPoint(x: 25, y: 25)) + aView.pin.topLeft(to: CGPoint(x: 25, y: 25)) expect(aView.frame).to(equal(CGRect(x: 25.0, y: 25.0, width: 100.0, height: 60.0))) } it("should position the aView's topLeft corner on its parent's topLeft corner") { - aView.layout.pinTopLeft() + aView.pin.topLeft() expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 100.0, height: 60.0))) } it("should position the aViewChild's topLeft corner on the specified view's topLeft corner") { -// aViewChild.layout.pinTopLeft(Pin.topLeft, of: aView) -// aViewChild.layout.pinTopLeft(aView.pin.topLeft) -// aViewChild.layout.pinTopLeft(<#T##pin: PinType##PinType#>, of: <#T##UIView#>) - aViewChild.layout.pinTopLeft(to: aView.pin.topLeft) +// aViewChild.pin.topLeftPin.topLeft, of: aView) +// aViewChild.pin.topLeftaView.pin.topLeft) +// aViewChild.pin.topLeft<#T##pin: PinType##PinType#>, of: <#T##UIView#>) + aViewChild.pin.topLeft(to: aView.anchor.topLeft) expect(aViewChild.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 50.0, height: 30.0))) } it("should position the aViewChild's topLeft corner on its parent sibling (bView)'s topLeft corner") { - aViewChild.layout.pinTopLeft(to: bView.pin.topLeft) + aViewChild.pin.topLeft(to: bView.anchor.topLeft) expect(aViewChild.frame).to(equal(CGRect(x: 20.0, y: 100.0, width: 50.0, height: 30.0))) } it("should position the bView's topLeft corner on its sibling's (aView) children (aViewChild)'s topLeft corner") { - bView.layout.pinTopLeft(to: aViewChild.pin.topLeft) + bView.pin.topLeft(to: aViewChild.anchor.topLeft) expect(bView.frame).to(equal(CGRect(x: 150.0, y: 120.0, width: 110.0, height: 80.0))) } it("should position the bViewChild's topLeft corner on its parent sibling's (aView) children (aViewChild)'s topLeft corner") { - bViewChild.layout.pinTopLeft(to: aViewChild.pin.topLeft) + bViewChild.pin.topLeft(to: aViewChild.anchor.topLeft) expect(bViewChild.frame).to(equal(CGRect(x: -10.0, y: -80.0, width: 60.0, height: 20.0))) } } @@ -111,244 +111,244 @@ class PinPointCoordinatesSpec: QuickSpec { describe("the result of the topCenter() and topCenter(to: UIView) methods") { it("should position the aView's topCenter corner at the specified position") { - aView.layout.pinTopCenter(to: CGPoint(x: 100, y: 100)) + aView.pin.topCenter(to: CGPoint(x: 100, y: 100)) expect(aView.frame).to(equal(CGRect(x: 50.0, y: 100.0, width: 100.0, height: 60.0))) } it("should position the aView's topCenter corner on its parent's topCenter corner") { - aView.layout.pinTopCenter() + aView.pin.topCenter() expect(aView.frame).to(equal(CGRect(x: 150.0, y: 0.0, width: 100.0, height: 60.0))) } it("should position the aViewChild's topCenter corner on the specified view's topCenter corner") { - aViewChild.layout.pinTopCenter(to: aView.pin.topCenter) + aViewChild.pin.topCenter(to: aView.anchor.topCenter) expect(aViewChild.frame).to(equal(CGRect(x: 25.0, y: 0.0, width: 50.0, height: 30.0))) } it("should position the aViewChild's topCenter corner on its parent sibling (bView)'s topCenter corner") { - aViewChild.layout.pinTopCenter(to: bView.pin.topCenter) + aViewChild.pin.topCenter(to: bView.anchor.topCenter) expect(aViewChild.frame).to(equal(CGRect(x: 50.0, y: 100.0, width: 50.0, height: 30.0))) } it("should position the bView's topCenter corner on its sibling's (aView) children (aViewChild)'s topCenter corner") { - bView.layout.pinTopCenter(to: aViewChild.pin.topCenter) + bView.pin.topCenter(to: aViewChild.anchor.topCenter) expect(bView.frame).to(equal(CGRect(x: 120.0, y: 120.0, width: 110.0, height: 80.0))) } it("should position the bViewChild's topCenter corner on its parent sibling's (aView) children (aViewChild)'s topCenter corner") { - bViewChild.layout.pinTopCenter(to: aViewChild.pin.topCenter) + bViewChild.pin.topCenter(to: aViewChild.anchor.topCenter) expect(bViewChild.frame).to(equal(CGRect(x: -15.0, y: -80.0, width: 60.0, height: 20.0))) } } // - // pinTopRight + // topRight // - describe("the result of the pinTopRight() and pinTopRight(to: UIView) methods") { - it("should position the aView's pinTopRight corner at the specified position") { - aView.layout.pinTopRight() + describe("the result of the topRight() and topRight(to: UIView) methods") { + it("should position the aView's topRight corner at the specified position") { + aView.pin.topRight() expect(aView.frame).to(equal(CGRect(x: 300.0, y: 0.0, width: 100.0, height: 60.0))) } - it("should position the aView's pinTopRight corner at the specified position") { - aViewChild.layout.pinTopRight(to: aView.pin.topRight) + it("should position the aView's topRight corner at the specified position") { + aViewChild.pin.topRight(to: aView.anchor.topRight) expect(aViewChild.frame).to(equal(CGRect(x: 50.0, y: 0.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinTopRight corner at the specified position") { - aViewChild.layout.pinTopRight(to: bView.pin.topRight) + it("should position the aView's topRight corner at the specified position") { + aViewChild.pin.topRight(to: bView.anchor.topRight) expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 60.0))) } - it("should position the aView's pinTopRight corner at the specified position") { - bView.layout.pinTopRight(to: aViewChild.pin.topRight) + it("should position the aView's topRight corner at the specified position") { + bView.pin.topRight(to: aViewChild.anchor.topRight) expect(bView.frame).to(equal(CGRect(x: 90.0, y: 120.0, width: 110.0, height: 80.0))) } - it("should position the aView's pinTopRight corner at the specified position") { - bViewChild.layout.pinTopRight(to: aViewChild.pin.topRight) + it("should position the aView's topRight corner at the specified position") { + bViewChild.pin.topRight(to: aViewChild.anchor.topRight) expect(bViewChild.frame).to(equal(CGRect(x: -20.0, y: -80.0, width: 60.0, height: 20.0))) } } // - // pinLeftCenter + // leftCenter // - describe("the result of the pinLeftCenter() and pinLeftCenter(to: UIView) methods") { - it("should position the aView's pinLeftCenter corner at the specified position") { - aView.layout.pinLeftCenter() + describe("the result of the leftCenter() and leftCenter(to: UIView) methods") { + it("should position the aView's leftCenter corner at the specified position") { + aView.pin.leftCenter() expect(aView.frame).to(equal(CGRect(x: 0.0, y: 170.0, width: 100.0, height: 60.0))) } - it("should position the aView's pinLeftCenter corner at the specified position") { - aViewChild.layout.pinLeftCenter(to: aView.pin.leftCenter) + it("should position the aView's leftCenter corner at the specified position") { + aViewChild.pin.leftCenter(to: aView.anchor.leftCenter) expect(aViewChild.frame).to(equal(CGRect(x: 0.0, y: 15.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinLeftCenter corner at the specified position") { - aViewChild.layout.pinLeftCenter(to: bView.pin.leftCenter) + it("should position the aView's leftCenter corner at the specified position") { + aViewChild.pin.leftCenter(to: bView.anchor.leftCenter) expect(aViewChild.frame).to(equal(CGRect(x: 20.0, y: 125.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinLeftCenter corner at the specified position") { - bView.layout.pinLeftCenter(to: aViewChild.pin.leftCenter) + it("should position the aView's leftCenter corner at the specified position") { + bView.pin.leftCenter(to: aViewChild.anchor.leftCenter) expect(bView.frame).to(equal(CGRect(x: 150.0, y: 95.0, width: 110.0, height: 80.0))) } - it("should position the aView's pinLeftCenter corner at the specified position") { - bViewChild.layout.pinLeftCenter(to: aViewChild.pin.leftCenter) + it("should position the aView's leftCenter corner at the specified position") { + bViewChild.pin.leftCenter(to: aViewChild.anchor.leftCenter) expect(bViewChild.frame).to(equal(CGRect(x: -10.0, y: -75.0, width: 60.0, height: 20.0))) } } /* // - // pinCenter + // center // - describe("the result of the pinCenter() and pinCenter(to: UIView) methods") { - it("should position the aView's pinCenter corner at the specified position") { - aView.layout.pinCenter() + describe("the result of the center() and center(to: UIView) methods") { + it("should position the aView's center corner at the specified position") { + aView.pin.center() expect(aView.frame).to(equal(CGRect(x: 150.0, y: 170.0, width: 100.0, height: 60.0))) } - it("should position the aView's pinCenter corner at the specified position") { - aViewChild.layout.pinCenter(to: aView) + it("should position the aView's center corner at the specified position") { + aViewChild.pin.center(to: aView) expect(aView.frame).to(equal(CGRect(x: 25.0, y: 15.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinCenter corner at the specified position") { - aViewChild.layout.pinCenter(to: bView) + it("should position the aView's center corner at the specified position") { + aViewChild.pin.center(to: bView) expect(aView.frame).to(equal(CGRect(x: 50.0, y: 125.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinCenter corner at the specified position") { - bView.layout.pinCenter(to: aViewChild) + it("should position the aView's center corner at the specified position") { + bView.pin.center(to: aViewChild) expect(aView.frame).to(equal(CGRect(x: 120.0, y: 95.0, width: 110.0, height: 80.0))) } - it("should position the aView's pinCenter corner at the specified position") { - bViewChild.layout.pinCenter(to: aViewChild) + it("should position the aView's center corner at the specified position") { + bViewChild.pin.center(to: aViewChild) expect(aView.frame).to(equal(CGRect(x: -15.0, y: -75.0, width: 60.0, height: 20.0))) } } // - // pinRightCenter + // rightCenter // - describe("the result of the pinRightCenter() and pinRightCenter(to: UIView) methods") { - it("should position the aView's pinRightCenter corner at the specified position") { - aView.layout.pinRightCenter() + describe("the result of the rightCenter() and rightCenter(to: UIView) methods") { + it("should position the aView's rightCenter corner at the specified position") { + aView.pin.rightCenter() expect(aView.frame).to(equal(CGRect(x: 300.0, y: 170.0, width: 100.0, height: 60.0))) } - it("should position the aView's pinRightCenter corner at the specified position") { - aViewChild.layout.pinRightCenter(to: aView) + it("should position the aView's rightCenter corner at the specified position") { + aViewChild.pin.rightCenter(to: aView) expect(aView.frame).to(equal(CGRect(x: 50.0, y: 15.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinRightCenter corner at the specified position") { - aViewChild.layout.pinRightCenter(to: bView) + it("should position the aView's rightCenter corner at the specified position") { + aViewChild.pin.rightCenter(to: bView) expect(aView.frame).to(equal(CGRect(x: 80.0, y: 125.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinRightCenter corner at the specified position") { - bView.layout.pinRightCenter(to: aViewChild) + it("should position the aView's rightCenter corner at the specified position") { + bView.pin.rightCenter(to: aViewChild) expect(aView.frame).to(equal(CGRect(x: 90.0, y: 95.0, width: 110.0, height: 80.0))) } - it("should position the aView's pinRightCenter corner at the specified position") { - bViewChild.layout.pinRightCenter(to: aViewChild) + it("should position the aView's rightCenter corner at the specified position") { + bViewChild.pin.rightCenter(to: aViewChild) expect(aView.frame).to(equal(CGRect(x: -20.0, y: -75.0, width: 60.0, height: 20.0))) } } // - // pinBottomLeft + // bottomLeft // - describe("the result of the pinBottomLeft() and pinBottomLeft(to: UIView) methods") { - it("should position the aView's pinBottomLeft corner at the specified position") { - aView.layout.pinBottomLeft() + describe("the result of the bottomLeft() and bottomLeft(to: UIView) methods") { + it("should position the aView's bottomLeft corner at the specified position") { + aView.pin.bottomLeft() expect(aView.frame).to(equal(CGRect(x: 0.0, y: 340.0, width: 100.0, height: 60.0))) } - it("should position the aView's pinBottomLeft corner at the specified position") { - aViewChild.layout.pinBottomLeft(to: aView) + it("should position the aView's bottomLeft corner at the specified position") { + aViewChild.pin.bottomLeft(to: aView) expect(aView.frame).to(equal(CGRect(x: 0.0, y: 30.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinBottomLeft corner at the specified position") { - aViewChild.layout.pinBottomLeft(to: bView) + it("should position the aView's bottomLeft corner at the specified position") { + aViewChild.pin.bottomLeft(to: bView) expect(aView.frame).to(equal(CGRect(x: 20.0, y: 150.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinBottomLeft corner at the specified position") { - bView.layout.pinBottomLeft(to: aViewChild) + it("should position the aView's bottomLeft corner at the specified position") { + bView.pin.bottomLeft(to: aViewChild) expect(aView.frame).to(equal(CGRect(x: 150.0, y: 70.0, width: 110.0, height: 80.0))) } - it("should position the aView's pinBottomLeft corner at the specified position") { - bViewChild.layout.pinBottomLeft(to: aViewChild) + it("should position the aView's bottomLeft corner at the specified position") { + bViewChild.pin.bottomLeft(to: aViewChild) expect(aView.frame).to(equal(CGRect(x: -10.0, y: -70.0, width: 60.0, height: 20.0))) } } // - // pinBottomCenter + // bottomCenter // - describe("the result of the pinBottomCenter() and pinBottomCenter(to: UIView) methods") { - it("should position the aView's pinBottomCenter corner at the specified position") { - aView.layout.pinBottomCenter() + describe("the result of the bottomCenter() and bottomCenter(to: UIView) methods") { + it("should position the aView's bottomCenter corner at the specified position") { + aView.pin.bottomCenter() expect(aView.frame).to(equal(CGRect(x: 150.0, y: 340.0, width: 100.0, height: 60.0))) } - it("should position the aView's pinBottomCenter corner at the specified position") { - aViewChild.layout.pinBottomCenter(to: aView) + it("should position the aView's bottomCenter corner at the specified position") { + aViewChild.pin.bottomCenter(to: aView) expect(aView.frame).to(equal(CGRect(x: 25.0, y: 30.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinBottomCenter corner at the specified position") { - aViewChild.layout.pinBottomCenter(to: bView) + it("should position the aView's bottomCenter corner at the specified position") { + aViewChild.pin.bottomCenter(to: bView) expect(aView.frame).to(equal(CGRect(x: 50.0, y: 150.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinBottomCenter corner at the specified position") { - bView.layout.pinBottomCenter(to: aViewChild) + it("should position the aView's bottomCenter corner at the specified position") { + bView.pin.bottomCenter(to: aViewChild) expect(aView.frame).to(equal(CGRect(x: 120.0, y: 70.0, width: 110.0, height: 80.0))) } - it("should position the aView's pinBottomCenter corner at the specified position") { - bViewChild.layout.pinBottomCenter(to: aViewChild) + it("should position the aView's bottomCenter corner at the specified position") { + bViewChild.pin.bottomCenter(to: aViewChild) expect(aView.frame).to(equal(CGRect(x: -15.0, y: -70.0, width: 60.0, height: 20.0))) } } // - // pinBottomRight + // bottomRight // - describe("the result of the pinBottomRight() and pinBottomRight(to: UIView) methods") { - it("should position the aView's pinBottomRight corner at the specified position") { - aView.layout.pinBottomRight() + describe("the result of the bottomRight() and bottomRight(to: UIView) methods") { + it("should position the aView's bottomRight corner at the specified position") { + aView.pin.bottomRight() expect(aView.frame).to(equal(CGRect(x: 300.0, y: 340.0, width: 100.0, height: 60.0))) } - it("should position the aView's pinBottomRight corner at the specified position") { - aViewChild.layout.pinBottomRight(to: aView) + it("should position the aView's bottomRight corner at the specified position") { + aViewChild.pin.bottomRight(to: aView) expect(aView.frame).to(equal(CGRect(x: 50.0, y: 30.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinBottomRight corner at the specified position") { - aViewChild.layout.pinBottomRight(to: bView) + it("should position the aView's bottomRight corner at the specified position") { + aViewChild.pin.bottomRight(to: bView) expect(aView.frame).to(equal(CGRect(x: 80.0, y: 150.0, width: 50.0, height: 30.0))) } - it("should position the aView's pinBottomRight corner at the specified position") { - bView.layout.pinBottomRight(to: aViewChild) + it("should position the aView's bottomRight corner at the specified position") { + bView.pin.bottomRight(to: aViewChild) expect(aView.frame).to(equal(CGRect(x: 90.0, y: 70.0, width: 110.0, height: 80.0))) } - it("should position the aView's pinBottomRight corner at the specified position") { - bViewChild.layout.pinBottomRight(to: aViewChild) + it("should position the aView's bottomRight corner at the specified position") { + bViewChild.pin.bottomRight(to: aViewChild) expect(aView.frame).to(equal(CGRect(x: -20.0, y: -70.0, width: 60.0, height: 20.0))) } }*/ diff --git a/MCSwiftLayoutTests/RelativePositionSpec.swift b/MCSwiftLayoutTests/RelativePositionSpec.swift index a3d9a0dc..938ba414 100644 --- a/MCSwiftLayoutTests/RelativePositionSpec.swift +++ b/MCSwiftLayoutTests/RelativePositionSpec.swift @@ -55,36 +55,36 @@ class RelativePositionSpec: QuickSpec { // describe("the result of above(of:aligned: left)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.above(of: aView, aligned: .left) + bView.pin.above(of: aView, aligned: .left) expect(bView.frame).to(equal(CGRect(x: 100.0, y: 60.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.above(of: aViewChild, aligned: .left) + bView.pin.above(of: aViewChild, aligned: .left) expect(bView.frame).to(equal(CGRect(x: 145.0, y: 110.0, width: 40.0, height: 40.0))) } } describe("the result of above(of:aligned: center)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.above(of: aView, aligned: .center) + bView.pin.above(of: aView, aligned: .center) expect(bView.frame).to(equal(CGRect(x: 180.0, y: 60.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.above(of: aViewChild, aligned: .center) + bView.pin.above(of: aViewChild, aligned: .center) expect(bView.frame).to(equal(CGRect(x: 165.0, y: 110.0, width: 40.0, height: 40.0))) } } describe("the result of above(of:aligned: right)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.above(of: aView, aligned: .right) + bView.pin.above(of: aView, aligned: .right) expect(bView.frame).to(equal(CGRect(x: 260.0, y: 60.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.above(of: aViewChild, aligned: .right) + bView.pin.above(of: aViewChild, aligned: .right) expect(bView.frame).to(equal(CGRect(x: 185.0, y: 110.0, width: 40.0, height: 40.0))) } } @@ -94,36 +94,36 @@ class RelativePositionSpec: QuickSpec { // describe("the result of left(of:aligned: .top)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.left(of: aView, aligned: .top) + bView.pin.left(of: aView, aligned: .top) expect(bView.frame).to(equal(CGRect(x: 60.0, y: 100.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.left(of: aViewChild, aligned: .top) + bView.pin.left(of: aViewChild, aligned: .top) expect(bView.frame).to(equal(CGRect(x: 105.0, y: 150.0, width: 40.0, height: 40.0))) } } describe("the result of left(of:aligned: .center)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.left(of: aView, aligned: .center) + bView.pin.left(of: aView, aligned: .center) expect(bView.frame).to(equal(CGRect(x: 60.0, y: 160.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.left(of: aViewChild, aligned: .center) + bView.pin.left(of: aViewChild, aligned: .center) expect(bView.frame).to(equal(CGRect(x: 105.0, y: 170.0, width: 40.0, height: 40.0))) } } describe("the result of left(of:aligned: .bottom)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.left(of: aView, aligned: .bottom) + bView.pin.left(of: aView, aligned: .bottom) expect(bView.frame).to(equal(CGRect(x: 60.0, y: 220.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.left(of: aViewChild, aligned: .bottom) + bView.pin.left(of: aViewChild, aligned: .bottom) expect(bView.frame).to(equal(CGRect(x: 105.0, y: 190.0, width: 40.0, height: 40.0))) } } @@ -133,36 +133,36 @@ class RelativePositionSpec: QuickSpec { // describe("the result of below(of:aligned: .left)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.below(of: aView, aligned: .left) + bView.pin.below(of: aView, aligned: .left) expect(bView.frame).to(equal(CGRect(x: 100.0, y: 260.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.below(of: aViewChild, aligned: .left) + bView.pin.below(of: aViewChild, aligned: .left) expect(bView.frame).to(equal(CGRect(x: 145.0, y: 230.0, width: 40.0, height: 40.0))) } } describe("the result of below(of:aligned: .center)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.below(of: aView, aligned: .center) + bView.pin.below(of: aView, aligned: .center) expect(bView.frame).to(equal(CGRect(x: 180.0, y: 260.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.below(of: aViewChild, aligned: .center) + bView.pin.below(of: aViewChild, aligned: .center) expect(bView.frame).to(equal(CGRect(x: 165.0, y: 230.0, width: 40.0, height: 40.0))) } } describe("the result of below(of:aligned: .right)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.below(of: aView, aligned: .right) + bView.pin.below(of: aView, aligned: .right) expect(bView.frame).to(equal(CGRect(x: 260.0, y: 260.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.below(of: aViewChild, aligned: .right) + bView.pin.below(of: aViewChild, aligned: .right) expect(bView.frame).to(equal(CGRect(x: 185.0, y: 230.0, width: 40.0, height: 40.0))) } } @@ -172,36 +172,36 @@ class RelativePositionSpec: QuickSpec { // describe("the result of right(of:aligned: .top)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.right(of: aView, aligned: .top) + bView.pin.right(of: aView, aligned: .top) expect(bView.frame).to(equal(CGRect(x: 300.0, y: 100.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.right(of: aViewChild, aligned: .top) + bView.pin.right(of: aViewChild, aligned: .top) expect(bView.frame).to(equal(CGRect(x: 225.0, y: 150.0, width: 40.0, height: 40.0))) } } describe("the result of right(of:aligned: .center)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.right(of: aView, aligned: .center) + bView.pin.right(of: aView, aligned: .center) expect(bView.frame).to(equal(CGRect(x: 300.0, y: 160.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.right(of: aViewChild, aligned: .center) + bView.pin.right(of: aViewChild, aligned: .center) expect(bView.frame).to(equal(CGRect(x: 225.0, y: 170.0, width: 40.0, height: 40.0))) } } describe("the result of right(of:aligned: .bottom)") { it("should adjust the bView position relative to its sibling (aView)") { - bView.layout.right(of: aView, aligned: .bottom) + bView.pin.right(of: aView, aligned: .bottom) expect(bView.frame).to(equal(CGRect(x: 300.0, y: 220.0, width: 40.0, height: 40.0))) } it("should adjust the bView position relative ot its sibling children (aViewChild)") { - bView.layout.right(of: aViewChild, aligned: .bottom) + bView.pin.right(of: aViewChild, aligned: .bottom) expect(bView.frame).to(equal(CGRect(x: 225.0, y: 190.0, width: 40.0, height: 40.0))) } } @@ -211,12 +211,12 @@ class RelativePositionSpec: QuickSpec { // describe("the result of above(of:)") { it("should adjust the bView bottom edge relative to its sibling (aView)") { - bView.layout.above(of: aView) + bView.pin.above(of: aView) expect(bView.frame).to(equal(CGRect(x: 160.0, y: 60.0, width: 40.0, height: 40.0))) } it("should adjust the bView bottom edge relative to its sibling (aView)") { - bView.layout.above(of: aViewChild) + bView.pin.above(of: aViewChild) expect(bView.frame).to(equal(CGRect(x: 160.0, y: 110.0, width: 40.0, height: 40.0))) } } @@ -226,12 +226,12 @@ class RelativePositionSpec: QuickSpec { // describe("the result of left(of:)") { it("should adjust the bView right edge relative to its sibling (aView)") { - bView.layout.left(of: aView) + bView.pin.left(of: aView) expect(bView.frame).to(equal(CGRect(x: 60.0, y: 200.0, width: 40.0, height: 40.0))) } it("should adjust the bView right edge relative to its sibling (aView)") { - bView.layout.left(of: aViewChild) + bView.pin.left(of: aViewChild) expect(bView.frame).to(equal(CGRect(x: 105.0, y: 200.0, width: 40.0, height: 40.0))) } } @@ -241,12 +241,12 @@ class RelativePositionSpec: QuickSpec { // describe("the result of below(of:)") { it("should adjust the bView top edge relative to its sibling (aView)") { - bView.layout.below(of: aView) + bView.pin.below(of: aView) expect(bView.frame).to(equal(CGRect(x: 160.0, y: 260.0, width: 40.0, height: 40.0))) } it("should adjust the bView top edge relative to its sibling (aView)") { - bView.layout.below(of: aViewChild) + bView.pin.below(of: aViewChild) expect(bView.frame).to(equal(CGRect(x: 160.0, y: 230.0, width: 40.0, height: 40.0))) } } @@ -256,12 +256,12 @@ class RelativePositionSpec: QuickSpec { // describe("the result of right(of:)") { it("should adjust the bView left edge relative to its sibling (aView)") { - bView.layout.right(of: aView) + bView.pin.right(of: aView) expect(bView.frame).to(equal(CGRect(x: 300.0, y: 200.0, width: 40.0, height: 40.0))) } it("should adjust the bView left edge relative to its sibling (aView)") { - bView.layout.right(of: aViewChild) + bView.pin.right(of: aViewChild) expect(bView.frame).to(equal(CGRect(x: 225.0, y: 200.0, width: 40.0, height: 40.0))) } }