- iOS 9.0+
- Xcode 10.0+
- Swift 4.2+
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
CocoaPods 1.1.0+ is required to build DCAutoLayout 1.0.0+.
To integrate DCAutoLayout into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'DCAutoLayout'
end
Then, run the following command:
$ pod install
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 DCAutoLayout into your Xcode project using Carthage, specify it in your Cartfile
:
github "DarielChen/DCAutoLayout"
Run carthage update
to build the framework and drag the built DCAutoLayout.framework
into your Xcode project.
If you prefer not to use either of the aforementioned dependency managers, you can integrate DCAutoLayout into your project manually.
import DCAutoLayout
class ViewController: UIViewController {
lazy var label = UILabel()
override func viewDidLoad() {
super.viewDidLoad()
label.backgroundColor = UIColor.groupTableViewBackground
view.addSubview(label)
label.layout {
$0.topAnchor == view.safeAreaTopAnchor + 20
$0.leadingAnchor == view.leadingAnchor + 20
$0.trailingAnchor == view.trailingAnchor - 20
$0.heightAnchor == 44
}
}
}
label.layout {
$0.topAnchor == view.topAnchor + 20
$0.leadingAnchor == view.leadingAnchor + 20
$0.trailingAnchor == view.trailingAnchor - 20
$0.bottomAnchor == view.bottomAnchor - 20
}
Or even shorter:
label.layout {
$0 == view.marign(20, 20, 20, 20)
}
You can use >=
or <=
to change Anchor.
label.layout {
$0.centerAnchor == view.centerAnchor
$0.widthAnchor == view.bounds.width - 40
$0.heightAnchor >= 44
}
set height to 88pts.
label.layout {
$0.heightAnchor == 88
}
label.layout {
$0 == view.marign(20, 20, 20, 20)
}
label.layout {
$0.sizeAnchor == view.size(100, 44)
}
label.layout {
$0.centerAnchor == view.centerAnchor
}
label.layout {
$0.heightAnchor >= 44
}
Update constraint.
label.layout {
$0.heightAnchor == 88
}
Set heightAnchor after remove heightAnchor.
label.layout {
$0.removeAnchor($0.heightAnchor)
$0.heightAnchor == 88
}
Set any anchor after remove all anchor.
label.removeAllAnchor()
label.layout {
$0.removeAnchor($0.heightAnchor)
$0.heightAnchor == 88
}
DCAutoLayout is released under the MIT license. See LICENSE for details.