I'm having an issue when trying to layout a view programatically and I cant seem to find a concise, non hacky way to fix it.
I'm using safeAreaInsets to size some elements in my view. This works well until I try it out on a pre iOS 11 device. Obviously, with the lack of safeAreaInsets the sizing of my subviews falls apart and everything becomes a mess. What do I fall back to when using older versions of iOS.
More specifically, what can I implement in the extension below that will work as expected?
extension UIView {
func compatibilityInsets() -> UIEdgeInsets {
if #available(iOS 11.0, *) {
return self.safeAreaInsets
} else {
//what goes here?
return self.olderVersionOfInsets
}
}
}
Here is an exmaple of how I might use this extension method:
var minimumHeaderHeight: CGFloat {
//allows the header height to be 70 below navigation bar
return 70 + view.compatibilityInsets().top
}