Created
January 30, 2018 16:39
-
-
Save aainaj/09c58f179a98bfe05684a417d0990fcb to your computer and use it in GitHub Desktop.
Safe Area 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
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