Last active
June 15, 2020 08:53
-
-
Save charlesmuchene/2d144f89b7bffa5988e7b790c4a103c8 to your computer and use it in GitHub Desktop.
Scroll View Insets
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
let scrollView = UIScrollView() | |
scrollView.backgroundColor = .systemGreen | |
scrollView.contentInset = UIEdgeInsets(top: 100, left: 100, bottom: 100, right: 100) | |
scrollView.contentSize = self.view.bounds.size | |
scrollView.translatesAutoresizingMaskIntoConstraints = false | |
self.view.addSubview(scrollView) | |
let views = ["scrollview": scrollView] | |
NSLayoutConstraint.activate([ | |
NSLayoutConstraint.constraints(withVisualFormat: "H:|[scrollview]|", metrics: nil, views: views), | |
NSLayoutConstraint.constraints(withVisualFormat: "V:|[scrollview]|", metrics: nil, views: views) | |
].flatMap({$0})) | |
let subview = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) | |
subview.backgroundColor = .white | |
scrollView.addSubview(subview) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment