Declarative UIKit for iOS apps
EXTENSION
UIStackViewpublic extension UIStackView
layoutMarginRelativevar layoutMarginRelative: Self
Set this Stack View’s isLayoutMarginsRelativeArrangement to true
hierarchyvar hierarchy: String
Recursively describe this stack and it’s subviews
horizontal(spacing:)@discardableResult func horizontal(spacing: CGFloat = 0) -> Self
Set the axis of this stack view to horizontal and set the spacing
| Name | Description |
|---|---|
| spacing | number to describe the spacing between arranged subviews |
vertical(spacing:)@discardableResult func vertical(spacing: CGFloat = 0) -> Self
Set the axis of this stack view to vertical and set the spacing
| Name | Description |
|---|---|
| spacing | number to describe the spacing between arranged subviews |
spacing(_:)@discardableResult func spacing(_ amount: CGFloat) -> Self
Set the spacing property of this stack view
| Name | Description |
|---|---|
| amount | the number to describe the spacing between arranged subviews |
distribution(_:)@discardableResult func distribution(_ style: Distribution) -> Self
Set the distribution of this stack view
| Name | Description |
|---|---|
| style | the distribution style |
add(arrangedSubviews:)@discardableResult func add(arrangedSubviews: [UIView?]) -> Self
Add an array of optional views to this stack view as arranged subviews, skipping nil views
| Name | Description |
|---|---|
| arrangedSubviews | the views to add as arranged subviews |
add(if:arrangedSubviews:)@discardableResult func add(if condition: Bool, arrangedSubviews: [UIView?]) -> Self
if a specific condition is true, then add the specified arranged subviews
| Name | Description |
|---|---|
| condition | the boolean condition to evaluate |
| arrangedSubviews | the views to add if the condition is true |
arrangedSubviews(includingStackViews:)func arrangedSubviews(includingStackViews: Bool) -> [UIView]
Recursive method that returns the arranged subviews
| Name | Description |
|---|---|
| includingSelf | should this view be a part of the returned array |
identifiers(includingStackViews:)func identifiers(includingStackViews: Bool) -> [String]
Recursively search this stack for accessibility identifiers
find(_:)func find<T>(_ type: T) -> [T]
Recursively search arranged subviews and any stack views arranged subviews for the given type and
| Name | Description |
|---|---|
| type | the given type |
hierarchy(description:level:stackIndex:)func hierarchy(description: String, level: Int = 0, stackIndex: Int = 0) -> String
Recursively describe this stack and it’s subviews
arrangedSubview(at:)func arrangedSubview(at index: Int) -> UIView?
Retrieve an arranged subview at the specified index
| Name | Description |
|---|---|
| index | the 0-based index of the arranged subview |
forEach(_:style:convertToView:)@discardableResult func forEach<T>(_ array: [T], style: DividerStyle = .innerOuter, convertToView: @escaping (T) -> UIView) -> Self
For each item in a given array, convert each element into a UIView, then add arranged subview
UIView| Name | Description |
|---|---|
| array | the data source |
| convertToView | how to format each element in the data source to a UIView |
forEach(_:style:completion:)@discardableResult func forEach<T>(_ array: [T], style: DividerStyle = .innerOuter, completion: @escaping (Int, T) -> Void) -> Self
For each item in a given array, call a completion to handle each index & element
| Name | Description |
|---|---|
| array | the data source |
| completion | index + element |
removeAllArrangedSubviews()func removeAllArrangedSubviews()
Clear all arranged subviews from this stack