Declarative UIKit for iOS apps
DHDeclarable
return UIStackView().declaredWith { stack in
stack.axis = .vertical
stack.distribution = .fill
stack.spacing = 10
stack.addArrangedSubview(...)
stack.addArrangedSubview(...)
stack.addArrangedSubview(...)
}
UIKit
objects: in this case UIStackView
:
extension Array where Element: UIView {
func add(to stackView: UIStackView) {
forEach { view in
stackView.addArrangedSubview(view)
}
}
}
UIStackView().declaredWith { stack in
stack.axis = .vertical
stack.distribution = .fill
stack.spacing = 10
[
UIView(),
].add(to: stack)
}
UIView
objects to be added to a stack viewUIKit
, using a familiar Swift syntax: square brackets!DHDeclarable
in the next article: DHDeclarable Best Practices, or view the map.