A simple class that leverages the power of Auto Layout to make UIStackView
scrollable.
- π Acts as a normal
UIStackView
, but scrollable. - π Subclassed from
UIScrollView
and usesUIStackView
under the hood. - πΆ Easy-to-understand codebase (~ 100 lines of code)
- π No external dependencies.
Download ScrollableStackView and manually import the file into your project.
- Initializing
let stackView = ScrollableStackView(frame: CGRect)
// or
let stackView = ScrollabelStackView(arrangedSubviews: [UIView]) // returns a new stack view object that manages the provided views
- Manage arranged subviews
var arrangedSubviews: [UIView] // list of views arranged by the stack view
func addArrangedSubview(UIView) // adds *a view* to the end of the arrangedSubviews
func addArrangedSubviews([UIView]) // adds *views* to the end of the arrangedSubviews
func insertArrangedSubview(UIView, at: Int) // adds the provided view to the array of arranged subviews at the specified index
func removeArrangedSubview(UIView) // removes the provided *view* from the stackβs array of arranged subviews
func removeArrangedSubviews([UIView]) // removes the provided *views* from the stackβs array of arranged subviews
- Configure the layout
var axis: NSLayoutConstraint.Axis // default .horizontal
var distribution: UIStackView.Distribution // default .fill
var aligment: UIStackView.Distribution // default .fill
var spacing: CGFloat // default 0.0
var insets: UIEdgeInsets // default .zero
I intent to keep this code base as simple as possible. Just as normal UIStackView
, which scrolls. If you are interested in a scrollable UIStackView
on steroids, check out AloeStackView by Airbnb.
- Inspired from Agnes Vasarhelyi's Scrollable UIStackView
- Official
UIStackView
documentation - Created by Joan Disho