extension UIApplication {
class func getsafeAreaBottomMargin() -> CGFloat {
if #available(iOS 11.0, *) {
let currentwindow = UIApplication.shared.windows.first
return (currentwindow?.safeAreaLayoutGuide.owningView?.frame.size.height)! - (currentwindow?.safeAreaLayoutGuide.layoutFrame.size.height)! - (currentwindow?.safeAreaLayoutGuide.layoutFrame.origin.y)!
}
else {
return 0
}
}
class func getsafeAreaTopMargin() -> CGFloat {
if #available(iOS 11.0, *) {
let currentwindow = UIApplication.shared.windows.first
return currentwindow?.safeAreaInsets.top ?? 0.0
}
else {
return 0
}
}
class func getsafeAreaLeftMagin() -> CGFloat {
if #available(iOS 11.0, *) {
let currentwindow = UIApplication.shared.windows.first
return currentwindow?.safeAreaInsets.left ?? 0.0
}
else {
return 0
}
}
class func getsafeAreaRightMagin() -> CGFloat {
if #available(iOS 11.0, *) {
let currentwindow = UIApplication.shared.windows.first
return currentwindow?.safeAreaInsets.right ?? 0.0
}
else {
return 0
}
}
}
사용방법
let safeTop = UIApplication.getsafeAreaTopMargin()
let safeBottom = UIApplication.getsafeAreaBottomMargin()
'Swift > UIViewController' 카테고리의 다른 글
[SWIFT]UIDocumentPickerViewController (0) | 2023.06.07 |
---|---|
[SWIFT]뷰 회전 관련 작업 : viewWillTransition (0) | 2023.04.24 |
[SWIFT]IOS16 화면 회전상태 확인 (0) | 2023.04.18 |
[SWIFT]상위 UIViewController 가져오기 (0) | 2023.04.17 |
[SWIFT]UIStoryboard 확장 UIViewController 쉽게 불러오기 (0) | 2023.04.17 |