Latest 1.0.1
Homepage https://github.com/strawb3rryx7/SBEasyLayout
License MIT
Platforms ios 9.0
Frameworks UIKit
Authors

SBEasyLayout 📐

MIT
Swift
iOSSwift

Layout your views easily!
You’ll be able to write your constraints by programmatically in a short time.

Firstly, Thanks to John Sundell (@johnsundell) for his "Building DSLs in Swift" post. It allows using auto layout stuffs in more effective and easy way.

Installation

SBEasyLayout is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'SBEasyLayout'

Examples

There are couple of usage examples:

NSLayoutAnchor

label.layout {
    $0.top == view.topAnchor + 5
    $0.leading == view.leadingAnchor + 5
    $0.trailing == view.trailingAnchor - 5
}
button.layout {
    $0.centerX == view.centerXAnchor
    $0.centerY == view.centerYAnchor
}
label.layout {
    $0.top == button.bottomAnchor + 20
    $0.leading == button.leadingAnchor
    $0.width <= view.widthAnchor - 40
}

NSLayoutDimension

view.layout {
    $0.width == 100
    $0.height == 100
}

or

view.layout {
    $0.width <= view.widthAnchor - 40
    $0.height <= view.heightAnchor - 50
}

or

with multiplier and constant

view.layout {
    $0.width <= (view.widthAnchor, 1.0, 1.0)
}

Besides that, As you see, We have a bunch of operators to represent Apple’s NSLayoutAnchor API’s some of methods, such as:
constraint(greaterThanOrEqualToConstant: CGFloat) -> NSLayoutConstraint,
constraint(lessThanOrEqualToConstant: CGFloat) -> NSLayoutConstraint

You can see them in the below.

NSLayoutAnchor operators & equivalents

Operator Actual method
== constraint(equalTo anchor: Self, constant: CGFloat) -> NSLayoutConstraint
>= constraint(greaterThanOrEqualToConstant: CGFloat) -> NSLayoutConstraint
<= constraint(lessThanOrEqualToConstant: CGFloat) -> NSLayoutConstraint

NSLayoutDimension operators & equivalents

Operator Actual method
== constraint(equalToConstant: CGFloat) -> NSLayoutConstraint
>= constraint(greaterThanOrEqualToConstant: CGFloat) -> NSLayoutConstraint
<= constraint(lessThanOrEqualToConstant: CGFloat) -> NSLayoutConstraint
== constraint(equalTo: Self, multiplier: CGFloat, constant: CGFloat) -> NSLayoutConstraint
>= constraint(greaterThanOrEqualTo: Self, multiplier: CGFloat, constant: CGFloat) -> NSLayoutConstraint
<= constraint(lessThanOrEqualTo: Self, multiplier: CGFloat, constant: CGFloat) -> NSLayoutConstraint

Also, you can pin the view to the superview’s edges, easily.

view.fillSuperview()

License

EasyLayout is released under the MIT license. See LICENSE.md for more information.

Latest podspec

{
    "name": "SBEasyLayout",
    "version": "1.0.1",
    "summary": "Layout your views easily. ud83dudcd0u2705",
    "description": "It makes the possible of creating constraints easily and efficient in programmatically way. u2705",
    "homepage": "https://github.com/strawb3rryx7/SBEasyLayout",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Batuhan Saka": "[email protected]"
    },
    "source": {
        "git": "https://github.com/strawb3rryx7/SBEasyLayout.git",
        "tag": "1.0.1"
    },
    "social_media_url": "https://twitter.com/strawb3rryx7",
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "SBEasyLayout/Classes/**/*",
    "swift_version": "4.2",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This