Lightweight, elegant and safe wrapper over auto layout.
Inspired by Layout Anchors and SnapKit.
Without overheads such as «extension UIView», «extension UILayoutGuide», «objc_setAssociatedObjectAssociatedObject», «objc_getAssociatedObject» etc.
By using Layout Anchors it would be as below
class ViewController: UIViewController {
private lazy var someView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(someView)
someView.translatesAutoresizingMaskIntoConstraints = false
someView.heightAnchor.constraint(equalToConstant: 30).isActive = true
someView.widthAnchor.constraint(equalToConstant: 30).isActive = true
someView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
someView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}
}
But if you support iOS 8 everything becomes worse, because of NSLayoutConstraint(item:attribute:relatedBy:blah:blah:blah:blah)
You may use "SuperPuperDuperLayout" like this
import SuperPuperDuperLayout
class ViewController: UIViewController {
private lazy var someView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(someView)
Layout.to(someView) {
$0.size.equal.value(.init(width: 30, height: 30))
$0.center.equalToSuperview.value(.zero)
}
}
}
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
CocoaPods 1.4.0+ is required to build SuperPuperDuperLayout 1.0.0.
To integrate SuperPuperDuperLayout into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target 'TargetName' do
pod 'SuperPuperDuperLayout'
end
Then, run the following command:
$ pod install
- iOS 8.0+
- Xcode 9.0+
- Swift 4.1+
- Alexander Zolotarev (@zolotarev_s)
SuperPuperDuperLayout is released under the MIT license. See LICENSE for details.