Created
October 31, 2017 11:57
-
-
Save IanKeen/aee3a8b4667309a95e2fc47ac3ee6ca6 to your computer and use it in GitHub Desktop.
Extension for constraints pointing to either the view or safeAreaLayoutGuide depending on availability
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
protocol LayoutGuideProvider { | |
var leadingAnchor: NSLayoutXAxisAnchor { get } | |
var trailingAnchor: NSLayoutXAxisAnchor { get } | |
var leftAnchor: NSLayoutXAxisAnchor { get } | |
var rightAnchor: NSLayoutXAxisAnchor { get } | |
var topAnchor: NSLayoutYAxisAnchor { get } | |
var bottomAnchor: NSLayoutYAxisAnchor { get } | |
var widthAnchor: NSLayoutDimension { get } | |
var heightAnchor: NSLayoutDimension { get } | |
var centerXAnchor: NSLayoutXAxisAnchor { get } | |
var centerYAnchor: NSLayoutYAxisAnchor { get } | |
} | |
extension UIView: LayoutGuideProvider { } | |
extension UILayoutGuide: LayoutGuideProvider { } | |
extension UIView { | |
var compatibleSafeAreaLayoutGuide: LayoutGuideProvider { | |
if #available(iOS 11, *) { | |
return safeAreaLayoutGuide | |
} else { | |
return self | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment