Created
August 19, 2019 03:56
-
-
Save d-date/294d4c791a273a502a68027a3a07d9f8 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 | |
open class VStackViewController: UIViewController { | |
public let scrollView: UIScrollView = .init() | |
public let stackView: UIStackView = { | |
let stackView: UIStackView = .init() | |
stackView.axis = .vertical | |
stackView.alignment = .fill | |
stackView.distribution = .equalSpacing | |
stackView.spacing = 0 | |
return stackView | |
}() | |
var components: [UIViewController] | |
public init(components: [UIViewController]) { | |
self.components = components | |
super.init(nibName: nil, bundle: nil) | |
} | |
public required init?(coder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
override open func viewDidLoad() { | |
super.viewDidLoad() | |
components.forEach { [weak self] in self?.addChild($0) } | |
view.addSubview(scrollView, constraints: .allEdges()) | |
scrollView.addSubview(stackView, constraints: .allEdges() + [equal(\.widthAnchor)]) | |
components.forEach { [weak self] in | |
guard let self = self else { return } | |
self.stackView.addArrangedSubview($0.view) | |
} | |
components.forEach { [weak self] in | |
guard let self = self else { return } | |
$0.didMove(toParent: self) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment