Skip to main content

Manual Integration

When needed, you can still use QuickLayout without the macro by manually managing the view hierarchy and overriding the layoutSubviews and sizeThatFits methods.

import QuickLayout

final class MyView: UIView {

private let label = {
let label = UILabel()
label.text = "Hello World!"
return label
}()

private let image = {
let image = UIImageView()
image.image = UIImage(systemName: "globe.americas")
return image
}()

init() {
super.init(frame: .zero)
self.addSubviews {
label
image
}
}

var body: Layout {
HStack {
label
Spacer(8)
image
}
}

override func layoutSubviews() {
super.layoutSubviews()
body.applyFrame(bounds)
}

override func sizeThatFits(_ proposedSize: CGSize) {
body.sizeThatFits(proposedSize)
}
}