Created
June 27, 2019 13:48
-
-
Save stefanpopa/eecadbda5929a545cfa96b023728f974 to your computer and use it in GitHub Desktop.
UIView layout anchors compat
This file contains hidden or 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
| extension UIView { | |
| var safeTopAnchor: NSLayoutYAxisAnchor { | |
| if #available(iOS 11.0, *) { | |
| return self.safeAreaLayoutGuide.topAnchor | |
| } | |
| return self.topAnchor | |
| } | |
| var safeLeftAnchor: NSLayoutXAxisAnchor { | |
| if #available(iOS 11.0, *){ | |
| return self.safeAreaLayoutGuide.leftAnchor | |
| } | |
| return self.leftAnchor | |
| } | |
| var safeRightAnchor: NSLayoutXAxisAnchor { | |
| if #available(iOS 11.0, *){ | |
| return self.safeAreaLayoutGuide.rightAnchor | |
| } | |
| return self.rightAnchor | |
| } | |
| var safeBottomAnchor: NSLayoutYAxisAnchor { | |
| if #available(iOS 11.0, *) { | |
| return self.safeAreaLayoutGuide.bottomAnchor | |
| } | |
| return self.bottomAnchor | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment