An AutoLayout Extension for iOS written in Swift 3 that is very easy to use.
Just copy the AutoLayout.swift
file to your project.
Add yourView as Subview
var yourView : UILabel = {
let label = UILabel()
label.text = "Your UILabel Text"
label.textAlignment = .center
label.translatesAutoresizingMaskIntoConstraints = false // Don't Forget to add this line.
return label
}()
view.addSubview(yourView)
yourView.anchorToTop(top: view.topAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor)
yourView.anchorWithConstantsToTop(top: view.topAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0)
If you want your view to connect to superview bottom edge set bottom: view.bottomAnchor
To add a secondView
below yourView
set it's top: as yourView.bottomAnchor
secondView.anchorWithConstantsToTop(top: yourView.bottomAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0)