Forked from falnatsheh/Simple Scrolling UIStackView with SnapKit
Created
October 10, 2024 00:21
-
-
Save Azuredark2781/06f41c90c65cce2a06af483ef4634a60 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