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