2οΈβ£SnapKit
Fall 2023 | Vin Bui
Installation
Using SnapKit
// NSLayout
NSLayoutConstraint.activate([
child.leadingAnchor.constraint(equalTo: parent.leadingAnchor),
child.topAnchor.constraint(equalTo: parent.topAnchor),
child.trailingAnchor.constraint(equalTo: parent.trailingAnchor),
child.bottomAnchor.constraint(equalTo: parent.bottomAnchor)
])
// SnapKit (note that we do not need commas)
child.snp.makeConstraints { make in
make.leading.equalToSuperview()
make.top.equalToSuperview()
make.trailing.equalToSuperview()
make.bottom.equalToSuperview()
}
// Or we can do the following
child.snp.makeConstraints { make in
make.leading.top.trailing.bottom.equalToSuperview()
}
// Or even the following
child.snp.makeConstraints { make in
make.edges.equalToSuperview()
}Last updated
Was this helpful?