Skip to content

Instantly share code, notes, and snippets.

  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Backwards compatible Safe Area Layout Guide API for iOS 10 and iOS 9
import UIKit
extension UIViewController {
var ft_safeAreaLayoutGuide: UILayoutGuide {
if #available(iOS 11.0, *) {
return view.safeAreaLayoutGuide
} else {
let id = "ft_safeAreaLayoutGuide"
if let layoutGuide = view.layoutGuides.filter({ $0.identifier == id }).first {
return layoutGuide
} else {
let layoutGuide = UILayoutGuide()
layoutGuide.identifier = id
layoutGuide.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true
layoutGuide.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
layoutGuide.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
layoutGuide.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor).isActive = true
return layoutGuide
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment