Created
June 8, 2018 14:14
-
-
Save superhard/a8cc57b87f9d8d7b7af9655f65c74444 to your computer and use it in GitHub Desktop.
Safe area UIView extension
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
//https://stackoverflow.com/questions/46317061/use-safe-area-layout-programmatically/46318300 | |
extension UIView { | |
var safeTopAnchor: NSLayoutYAxisAnchor { | |
if #available(iOS 11.0, *) { | |
return self.safeAreaLayoutGuide.topAnchor | |
} else { | |
return self.topAnchor | |
} | |
} | |
var safeLeftAnchor: NSLayoutXAxisAnchor { | |
if #available(iOS 11.0, *){ | |
return self.safeAreaLayoutGuide.leftAnchor | |
}else { | |
return self.leftAnchor | |
} | |
} | |
var safeRightAnchor: NSLayoutXAxisAnchor { | |
if #available(iOS 11.0, *){ | |
return self.safeAreaLayoutGuide.rightAnchor | |
}else { | |
return self.rightAnchor | |
} | |
} | |
var safeBottomAnchor: NSLayoutYAxisAnchor { | |
if #available(iOS 11.0, *) { | |
return self.safeAreaLayoutGuide.bottomAnchor | |
} else { | |
return self.bottomAnchor | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment