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
// in your UIViewController | |
func setupMySubview() { | |
let topInset = compatibleSafeInsets.top | |
let bottomInset = compatibleSafeInsets.bottom | |
let leftInset = compatibleSafeInsets.left | |
let rightInset = compatibleSafeInsets.right | |
let height = view.frame.size.height - bottomInset - topInset | |
let width = view.frame.size.width - leftInset - rightInset | |
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
extension UIViewController { | |
var compatibleSafeInsets: UIEdgeInsets { | |
if #available(iOS 11, *) { | |
return view.safeAreaInsets | |
} else { | |
return UIEdgeInsetsMake(topLayoutGuide.length, 0, bottomLayoutGuide.length, 0) | |
} | |
} | |
} |
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
extension UIView { | |
var safeTopAnchor: NSLayoutYAxisAnchor { | |
if #available(iOS 11.0, *) { | |
return safeAreaLayoutGuide.topAnchor | |
} else { | |
return 0 | |
} | |
} | |
var safeBottomAnchor: NSLayoutYAxisAnchor { |
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
extension UIViewController { | |
var safeTopAnchor: NSLayoutYAxisAnchor { | |
if #available(iOS 11.0, *) { | |
return view.safeAreaLayoutGuide.topAnchor | |
} else { | |
return topLayoutGuide.bottomAnchor | |
} | |
} | |
var safeBottomAnchor: NSLayoutYAxisAnchor { |