A collection of additional layout anchor types meant to complement UIKit's existing constraint system.
- iOS 13
- Xcode 13
- Swift 5.5
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate the library into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'Squidward', '1.4.2'
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler.
dependencies: [
.package(url: "https://github.com/berbschloe/Squidward.git", from: "1.4.2")
]
It would be recommended to add the library globally because it can get annoying importing it everywhere.
// Add this to a GlobalImports.swift
@_exported import Squidward
let childView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
NSLayoutConstraint.activate([
childView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 10),
childView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 10),
childView.topAnchor.constraint(equalTo: view.topAnchor, constant: -10),
childView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -10),
])
}
let childView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
NSLayoutConstraint.activate {
childView.edgeAnchors.constraint(equalTo: view.edgeAnchors, constant: 10)
}
}
childView.edgeAnchors.constraint(equalTo: view.edgeAnchors) // default zero constant
childView.edgeAnchors.constraint(edges: [.left, .right, .top], equalTo: view.edgeAnchors) // constrain specific edges
childView.edgeAnchors.constraint(
equalTo: view.edgeAnchors,
constant: UIEdgeInsets(top: 10, left: 20, bottom: 30, right: 40) // custom insets with no need to apply a negative
)