Skip to content

Instantly share code, notes, and snippets.

@PtitChevreuil
Last active November 2, 2017 11:03
Show Gist options
  • Save PtitChevreuil/4f4da5f97dd506225fd0de39c94f0c37 to your computer and use it in GitHub Desktop.
Save PtitChevreuil/4f4da5f97dd506225fd0de39c94f0c37 to your computer and use it in GitHub Desktop.
// in your UIViewController
func setupMySubview() {
let topInset = compatibleSafeInsets.top
let bottomInset = compatibleSafeInsets.bottom
let leftInset = compatibleSafeInsets.left
let rightInset = compatibleSafeInsets.right
let height = view.frame.size.height - bottomInset - topInset
let width = view.frame.size.width - leftInset - rightInset
mySubview.frame = CGRect(x: leftInset, y: topInset, width: width, height: height)
}
// This is called on both iOS 11 and 10
override func viewDidLayoutSubviews() {
setupMySubview()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment