Created
June 19, 2022 14:02
-
-
Save yefga/b1e72178e0b1b3d74eda6864823dbcb7 to your computer and use it in GitHub Desktop.
Embed all UIViews inside 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
extension Array where Element: UIView { | |
func embedInScroll(after view: UIView) { | |
let scrollView = UIScrollView() | |
view.addSubview(scrollView) | |
scrollView.translatesAutoresizingMaskIntoConstraints = false | |
scrollView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true | |
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true | |
scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true | |
scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true | |
forEach { element in | |
scrollView.addSubview(element) | |
element.translatesAutoresizingMaskIntoConstraints = false | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment