SimpleLayout helps you to using auto layout very easily
To run the example project, clone the repo, and run pod install
from the Example directory first.
let top = NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: self, attribute: .top, multiplier: 1.0, constant: -10)
let trailing = NSLayoutConstraint(item: view, attribute: .trailing, relatedBy: .equal, toItem: self, attribute: .trailing, multiplier: 1.0, constant: 10)
let width = NSLayoutConstraint(item: view, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 30)
let height = NSLayoutConstraint(item: view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 30)
view.addConstraints([width, height])
view.layoutIfNeeded()
self.addConstraints([top, trailing])
self.layoutIfNeeded()
view.layout
.top(-10)
.trailing(10)
.width(fixed: 30)
.height(fixed: 30)
import UIKit
import SimpleLayout
class FillExampleViewController: UIViewController {
private lazy var subview: UIView = {
let label = UILabel()
label.text = "subview"
label.textColor = .white
let subview = UIView()
subview.backgroundColor = .red
subview.addSubview(label)
label.layout
.leading()
.top()
.width(fixed: 0, relation: .greaterThanOrEqual)
.height(fixed: 0, relation: .greaterThanOrEqual)
return subview
}()
override func viewDidLoad() {
super.viewDidLoad()
self.edgesForExtendedLayout = .bottom
let label = UILabel()
label.text = "view"
self.view.addSubview(label)
self.view.addSubview(subview)
label.layout
.leading()
.top()
.width(fixed: 0, relation: .greaterThanOrEqual)
.height(fixed: 0, relation: .greaterThanOrEqual)
subview.layout.fill(leading: 30, top: 30, trailing: -30, bottom: -30)
}
}
import UIKit
import SimpleLayout
class ChainExampleViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.edgesForExtendedLayout = .bottom
let subview1 = label(backgroundColor: .red, text: "subview1")
let subview2 = label(backgroundColor: .purple, text: "subview2")
let subview3 = label(backgroundColor: .blue, text: "subview3")
self.view.addSubview(subview1)
self.view.addSubview(subview2)
self.view.addSubview(subview3)
subview1.layout
.leading()
.top()
.width()
.height(fixed: 150)
subview2.layout
.leading(by: subview1)
.top(by: subview1, attribute: .bottom)
.width(fixed: self.view.width/2)
.bottom()
subview3.layout
.leading(by: subview2, attribute: .trailing)
.top(by: subview2)
.trailing()
.bottom()
}
private func label(backgroundColor: UIColor, text: String) -> UILabel {
let label = UILabel()
label.backgroundColor = backgroundColor
label.text = text
label.textAlignment = .center
label.textColor = .white
return label
}
}
iOS SDK 8.0 equal or higher
SimpleLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "SimpleLayout-Swift"
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate Alamofire into your Xcode project using Carthage, specify it in your Cartfile
:
github "pisces/SimpleLayout" ~> 1.0.0
Run carthage update
to build the framework and drag the built SimpleLayout.framework
into your Xcode project.
Steve Kim, [email protected]
SimpleLayout is available under the MIT license. See the LICENSE file for more info.