Skip to content

Instantly share code, notes, and snippets.

@oconnelltoby
Last active September 26, 2021 21:55
Show Gist options
  • Save oconnelltoby/4dd33387a3744a758d1feac9582e0000 to your computer and use it in GitHub Desktop.
Save oconnelltoby/4dd33387a3744a758d1feac9582e0000 to your computer and use it in GitHub Desktop.
UIStackView in a UIScrollView
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