Skip to content

Instantly share code, notes, and snippets.

@j-nguyen
Created September 23, 2017 16:40
Show Gist options
  • Save j-nguyen/5e0494d011126541b7af63244ae368bd to your computer and use it in GitHub Desktop.
Save j-nguyen/5e0494d011126541b7af63244ae368bd to your computer and use it in GitHub Desktop.
Supporting iPhone X

Supporting iPhone X Sizes

Using Storyboard

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):

Storybaord

Programmatically

	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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment