Last active
September 26, 2021 21:55
-
-
Save oconnelltoby/4dd33387a3744a758d1feac9582e0000 to your computer and use it in GitHub Desktop.
UIStackView in a UIScrollView
This file contains 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 | |
public extension UIScrollView { | |
convenience init(stackView: UIStackView) { | |
self.init(frame: .zero) | |
stackView.translatesAutoresizingMaskIntoConstraints = false | |
addSubview(stackView) | |
NSLayoutConstraint.activate([ | |
stackView.topAnchor.constraint(equalTo: contentLayoutGuide.topAnchor), | |
stackView.bottomAnchor.constraint(equalTo: contentLayoutGuide.bottomAnchor), | |
stackView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor), | |
stackView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor), | |
contentLayoutGuide.widthAnchor.constraint(equalTo: widthAnchor), | |
]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment