Skip to content

Instantly share code, notes, and snippets.

@aainaj
Created January 30, 2018 16:39
Show Gist options
  • Save aainaj/09c58f179a98bfe05684a417d0990fcb to your computer and use it in GitHub Desktop.
Save aainaj/09c58f179a98bfe05684a417d0990fcb to your computer and use it in GitHub Desktop.
Safe Area Insets
import UIKit
class ViewController: UIViewController {
let wrapperView = UIView()
let cyanView = UIView()
override func viewDidLoad() {
view.backgroundColor = .green
view.addSubview(wrapperView)
wrapperView.addSubview(cyanView)
wrapperView.backgroundColor = .red
wrapperView.translatesAutoresizingMaskIntoConstraints = false
cyanView.backgroundColor = .cyan
cyanView.translatesAutoresizingMaskIntoConstraints = false
}
override func viewDidLayoutSubviews() {
wrapperView.frame = CGRect(x: view.frame.origin.x,
y: view.safeAreaInsets.top,
width: view.frame.size.width,
height: view.frame.size.height - view.safeAreaInsets.top)
cyanView.frame = CGRect(x: wrapperView.layoutMargins.left,
y: wrapperView.layoutMargins.top,
width: wrapperView.frame.size.width - wrapperView.layoutMargins.left-wrapperView.layoutMargins.right,
height: 100)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment