/ScrollableStackView

๐Ÿ„โ€โ™€๏ธ A UIStackView, which scrolls.

Primary LanguageSwiftMIT LicenseMIT

ScrollableStackView

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 uses UIStackView under the hood.
  • ๐Ÿ‘ถ Easy-to-understand codebase (~ 100 lines of code)
  • ๐ŸŽ‰ No external dependencies.

โš™๏ธ Installation

Download ScrollableStackView and manually import the file into your project.

๐Ÿ“š Usage

  • 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.

๐Ÿ™ Acknowledgements