Forked from falnatsheh/Simple Scrolling UIStackView with SnapKit
Created
November 4, 2022 04:31
-
-
Save nguyentrungnam-mvl/de9f34ab1e638d3c7ad341926a150209 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| import SnapKit | |
| class ViewController: UIViewController { | |
| var scrollView: UIScrollView! | |
| var stackView: UIStackView! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| scrollView = UIScrollView() | |
| scrollView.translatesAutoresizingMaskIntoConstraints = false | |
| view.addSubview(scrollView) | |
| scrollView.snp.makeConstraints { (make) in | |
| make.edges.equalToSuperview() | |
| } | |
| stackView = UIStackView() | |
| stackView.translatesAutoresizingMaskIntoConstraints = false | |
| stackView.axis = .horizontal | |
| scrollView.addSubview(stackView) | |
| stackView.snp.makeConstraints { (make) in | |
| make.edges.equalToSuperview() | |
| } | |
| for _ in 1 ..< 100 { | |
| let vw = UIButton(type: UIButtonType.system) | |
| vw.setTitle("Button", for: []) | |
| stackView.addArrangedSubview(vw) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment