Last active
February 26, 2019 13:51
-
-
Save noxt/24af929d8c3e477f6425a05ca6be6c00 to your computer and use it in GitHub Desktop.
UIViewController+SafeAnchor
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 | |
public extension UIViewController { | |
public var safeTopAnchor: NSLayoutYAxisAnchor { | |
if #available(iOS 11, *) { | |
return view.safeAreaLayoutGuide.topAnchor | |
} else { | |
return topLayoutGuide.bottomAnchor | |
} | |
} | |
public var safeBottomAnchor: NSLayoutYAxisAnchor { | |
if #available(iOS 11, *) { | |
return view.safeAreaLayoutGuide.bottomAnchor | |
} else { | |
return bottomLayoutGuide.topAnchor | |
} | |
} | |
public var safeLeadingAnchor: NSLayoutXAxisAnchor { | |
if #available(iOS 11, *) { | |
return view.safeAreaLayoutGuide.leadingAnchor | |
} else { | |
return view.leadingAnchor | |
} | |
} | |
public var safeTrailingAnchor: NSLayoutXAxisAnchor { | |
if #available(iOS 11, *) { | |
return view.safeAreaLayoutGuide.trailingAnchor | |
} else { | |
return view.trailingAnchor | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment