To support the new sizes, Apple gave us a new constraint, called the safeLayoutGuide
margin. Basically, Apple has already adjusted the sizes for you.
Make sure it looks like this (Just make sure the safeAreaLayoutGuide is ticked):
fileprivate func prepareView() {
let testView = UIView()
testView.backgroundColor = .red
testView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(testView)
testView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
}
use the property, safeAreaLayoutGuide
to help assist you. If you're using SnapKit
, which is the popular iOS library for constraints, you'll only need to update your library to get
it to support iPhone X's screen.