Forked from fedetrim/UIViewController+SafeAreaLayoutGuide.swift
Created
April 16, 2018 19:49
-
-
Save marianoabdala/2e873480646d3f85d1aae21813554658 to your computer and use it in GitHub Desktop.
Backwards compatible Safe Area Layout Guide API for iOS 10 and iOS 9
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 | |
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 | |
view.addLayoutGuide(layoutGuide) | |
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