Skip to content

Instantly share code, notes, and snippets.

@ranmyfriend
Created March 8, 2019 12:03
Show Gist options
  • Save ranmyfriend/a081dae969a7b39fd9feb0578962af7e to your computer and use it in GitHub Desktop.
Save ranmyfriend/a081dae969a7b39fd9feb0578962af7e to your computer and use it in GitHub Desktop.
extension UIView {
var leftAnchor: NSLayoutXAxisAnchor {
return iOS11NAbove ? safeAreaLayoutGuide.leftAnchor : self.leftAnchor
}
var rightAnchor: NSLayoutXAxisAnchor {
return iOS11NAbove ? safeAreaLayoutGuide.rightAnchor : self.rightAnchor
}
var topAnchor: NSLayoutYAxisAnchor {
return iOS11NAbove ? safeAreaLayoutGuide.topAnchor : self.topAnchor
}
var bottomAnchor: NSLayoutYAxisAnchor {
return iOS11NAbove ? safeAreaLayoutGuide.bottomAnchor : self.bottomAnchor
}
private var iOS11NAbove: Bool {
if #available(iOS 11.0, *) {
return true
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment