https://github.com/jdisho/scrollablestackview
πββοΈ A UIStackView, which scrolls.
https://github.com/jdisho/scrollablestackview
swift uistackview uistackview-scrollable
Last synced: 10 months ago
JSON representation
πββοΈ A UIStackView, which scrolls.
- Host: GitHub
- URL: https://github.com/jdisho/scrollablestackview
- Owner: jdisho
- License: mit
- Created: 2019-05-18T18:33:28.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-20T20:21:06.000Z (about 7 years ago)
- Last Synced: 2024-01-14T14:21:47.132Z (over 2 years ago)
- Topics: swift, uistackview, uistackview-scrollable
- Language: Swift
- Homepage:
- Size: 34.2 KB
- Stars: 16
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://github.com/jdisho/ScrollableStackView/blob/master/ScrollableStackView/ScrollableStackView.swift) and manually import the file into your project.
## π Usage
- Initializing
```swift
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
```swift
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
```swift
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](https://github.com/airbnb/AloeStackView) by [Airbnb](https://github.com/airbnb).*
## π Acknowledgements
- Inspired from [Agnes Vasarhelyi](https://twitter.com/vasarhelyia)'s [Scrollable UIStackView](https://blog.alltheflow.com/scrollable-uistackview/)
- Official `UIStackView` [documentation](https://developer.apple.com/documentation/uikit/uistackview?changes=latest_minor)
- Created by [Joan Disho](twitter.com/_disho)