Skip to content

Commit

Permalink
Add abreast methods
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-liu committed Mar 4, 2017
1 parent c671e86 commit 2dca25d
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//: [Home](Home) | [Previous](@previous) | [Next](@next)

import UIKit
import FormationLayout

/*:
## Abreast
----
- layout[logo].below(topLayoutGuide, plus: 10)
- logo.top == topLayoutGuide.bottom + 10
- layout[copyright].above(bottomLayoutGuide, minus: 10)
- copyright.bottom == bottomLayoutGuide.top - 10
*/

demo { canvas, icon1, icon2, icon3 in
let layout = FormationLayout(rootView: canvas)
layout[icon1].center(equalTo: canvas)
layout[icon2].before(icon1).above(icon1)
layout[icon3].after(icon1).below(icon1)
}

//: [Home](Home) | [Previous](@previous) | [Next](@next)
1 change: 1 addition & 0 deletions Documentation/Doc.playground/contents.xcplayground
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<page name='Anchors'/>
<page name='Helpers'/>
<page name='Pin'/>
<page name='Abreast'/>
<page name='Group'/>
<page name='Condition'/>
<page name='Priority'/>
Expand Down
Binary file added Documentation/Images/Abreast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions FormationLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
2030A2851DE4C7410035E9D8 /* ConstraintMaker+Pin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2030A2841DE4C7410035E9D8 /* ConstraintMaker+Pin.swift */; };
20698A181DEA45B300FCDC3D /* GroupConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20698A171DEA45B300FCDC3D /* GroupConstraintMaker.swift */; };
20BB2DA21DE6D836007455B9 /* ConstraintMaker+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20BB2DA11DE6D836007455B9 /* ConstraintMaker+Helpers.swift */; };
20CE17881E6A8709006DBE5C /* ConstraintMaker+Abreast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20CE17871E6A8709006DBE5C /* ConstraintMaker+Abreast.swift */; };
20DA6D011DE610F100D40F93 /* ConstraintMaker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20DA6D001DE610F100D40F93 /* ConstraintMaker.swift */; };
52D6D9871BEFF229002C0205 /* FormationLayout.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* FormationLayout.framework */; };
52D6D9981BEFF375002C0205 /* FormationLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52D6D9961BEFF375002C0205 /* FormationLayout.swift */; };
Expand All @@ -38,6 +39,7 @@
20BB2D9F1DE6BAAC007455B9 /* anchors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = anchors.swift; sourceTree = "<group>"; };
20BB2DA11DE6D836007455B9 /* ConstraintMaker+Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "ConstraintMaker+Helpers.swift"; path = "Sources/ConstraintMaker+Helpers.swift"; sourceTree = "<group>"; };
20BB2DA31DE6DB7D007455B9 /* helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = helpers.swift; sourceTree = "<group>"; };
20CE17871E6A8709006DBE5C /* ConstraintMaker+Abreast.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "ConstraintMaker+Abreast.swift"; path = "Sources/ConstraintMaker+Abreast.swift"; sourceTree = "<group>"; };
20DA6D001DE610F100D40F93 /* ConstraintMaker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConstraintMaker.swift; path = Sources/ConstraintMaker.swift; sourceTree = "<group>"; };
52D6D97C1BEFF229002C0205 /* FormationLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FormationLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; };
52D6D9861BEFF229002C0205 /* FormationLayout-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "FormationLayout-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -85,6 +87,7 @@
2030A2821DE4C6830035E9D8 /* ConstraintMaker+Anchors.swift */,
20BB2DA11DE6D836007455B9 /* ConstraintMaker+Helpers.swift */,
2030A2841DE4C7410035E9D8 /* ConstraintMaker+Pin.swift */,
20CE17871E6A8709006DBE5C /* ConstraintMaker+Abreast.swift */,
2030A2801DE4BECF0035E9D8 /* ItemConstraintMaker.swift */,
20698A171DEA45B300FCDC3D /* GroupConstraintMaker.swift */,
20BB2D9E1DE6BA88007455B9 /* Scripts */,
Expand Down Expand Up @@ -238,6 +241,7 @@
files = (
200020381DE96F1100B33F58 /* ConstraintCondition.swift in Sources */,
2030A2811DE4BECF0035E9D8 /* ItemConstraintMaker.swift in Sources */,
20CE17881E6A8709006DBE5C /* ConstraintMaker+Abreast.swift in Sources */,
52D6D9981BEFF375002C0205 /* FormationLayout.swift in Sources */,
2030A2851DE4C7410035E9D8 /* ConstraintMaker+Pin.swift in Sources */,
20BB2DA21DE6D836007455B9 /* ConstraintMaker+Helpers.swift in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ demo { canvas, icon1, icon2, icon3 in

![Pin](https://github.com/evan-liu/FormationLayout/blob/master/Documentation/Images/Pin.png)

### Abreast

- layout[logo].below(topLayoutGuide, plus: 10)
- logo.top == topLayoutGuide.bottom + 10
- layout[copyright].above(bottomLayoutGuide, minus: 10)
- copyright.bottom == bottomLayoutGuide.top - 10

```swift
demo { canvas, icon1, icon2, icon3 in
let layout = FormationLayout(rootView: canvas)
layout[icon1].center(equalTo: canvas)
layout[icon2].before(icon1).above(icon1)
layout[icon3].after(icon1).below(icon1)
}
```

![Abreast](https://github.com/evan-liu/FormationLayout/blob/master/Documentation/Images/Abreast.png)

### Group

`layout.group(view1, view2)` will create same constraints for
Expand Down
74 changes: 74 additions & 0 deletions Sources/ConstraintMaker+Abreast.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* FormationLayout
*
* Copyright (c) 2016 Evan Liu. Licensed under the MIT license, as follows:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import UIKit

@available(iOS 7.0, *)
extension ConstraintMaker {

/// Make item.top equalTo item2.bottom + constant
@discardableResult
public func below(_ item2: UILayoutSupport, plus constant: CGFloat = 0, at priority: UILayoutPriority = UILayoutPriorityRequired) -> Self {
return makeConstraint(attribute: .top, relatedBy: .equal, toItem: item2, attribute: .bottom, multiplier: 1, constant: constant, priority: priority)
}

/// Make item.bottom equalTo item2.top - constant
@discardableResult
public func above(_ item2: UILayoutSupport, minus constant: CGFloat = 0, at priority: UILayoutPriority = UILayoutPriorityRequired) -> Self {
return makeConstraint(attribute: .bottom, relatedBy: .equal, toItem: item2, attribute: .top, multiplier: 1, constant: -constant, priority: priority)
}

}

extension ConstraintMaker {

/// Make item.top equalTo item2.bottom + constant
@discardableResult
public func below(_ item2: Item, plus constant: CGFloat = 0, at priority: UILayoutPriority = UILayoutPriorityRequired) -> Self {
return top(equalTo: .bottom, of: item2, plus: constant, at: priority)
}

/// Make item.bottom equalTo item2.top - constant
@discardableResult
public func above(_ item2: Item, minus constant: CGFloat = 0, at priority: UILayoutPriority = UILayoutPriorityRequired) -> Self {
return bottom(equalTo: .top, of: item2, minus: constant, at: priority)
}

}

extension ConstraintMaker {

/// Make item.leading equalTo item2.trailing + constant
@discardableResult
public func after(_ item2: Item, plus constant: CGFloat = 0, at priority: UILayoutPriority = UILayoutPriorityRequired) -> Self {
return leading(equalTo: .trailing, of: item2, plus: constant, at: priority)
}

/// Make item.trailing equalTo item2.leading - constant
@discardableResult
public func before(_ item2: Item, minus constant: CGFloat = 0, at priority: UILayoutPriority = UILayoutPriorityRequired) -> Self {
return trailing(equalTo: .leading, of: item2, minus: constant, at: priority)
}

}

0 comments on commit 2dca25d

Please sign in to comment.