Last active
June 24, 2019 03:33
-
-
Save jonblatho/01b4ea0388881e7f7049957ff3a298a2 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
extension UIStackView { | |
/** | |
Fills the given scroll view with this stack view. This method automatically creates | |
and activates constraints and adds the stack view to the scroll view. | |
- parameter scrollView: The scroll view into which this stack view should be inserted. | |
*/ | |
internal func attachToScrollView(_ scrollView: UIScrollView) { | |
// Add this stack view to the given UIScrollView | |
scrollView.addSubview(self) | |
// Disable automatic constraints from autoresizing mask | |
self.translatesAutoresizingMaskIntoConstraints = false | |
// Create and activate constraints | |
self.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor).isActive = true | |
self.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor).isActive = true | |
self.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true | |
self.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor).isActive = true | |
self.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment