Skip to content

Instantly share code, notes, and snippets.

@charlesmuchene
Last active June 15, 2020 08:53
Show Gist options
  • Save charlesmuchene/2d144f89b7bffa5988e7b790c4a103c8 to your computer and use it in GitHub Desktop.
Save charlesmuchene/2d144f89b7bffa5988e7b790c4a103c8 to your computer and use it in GitHub Desktop.
Scroll View Insets
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