반응형
Swift의 상태 표시 줄 높이
Swift에서 프로그래밍 방식으로 상태 표시 줄의 높이를 어떻게 얻을 수 있습니까?
Objective-C에서는 다음과 같습니다.
[UIApplication sharedApplication].statusBarFrame.size.height.
어떤 문제가 있습니까 스위프트 2.X는 :
UIApplication.sharedApplication().statusBarFrame.size.height
Swift 3 또는 Swift 4 :
UIApplication.shared.statusBarFrame.height
UIKit
가져 왔는지 확인
import UIKit
Swift는 다른 언어 일뿐입니다. API 요소는 동일합니다. 아마도 다음과 같습니다.
let app = UIApplication.sharedApplication()
let height = app.statusBarFrame.size.height
Objective-C와 같습니다.
var screenStatusBarHeight: CGFloat {
return UIApplication.sharedApplication().statusBarFrame.height
}
이것은 다음에서 표준 변수로 포함됩니다.
https://github.com/goktugyil/EZSwiftExtensions
이것이 내가 사용하는 것입니다.
struct Screen {
static var width: CGFloat {
return UIScreen.main.bounds.width
}
static var height: CGFloat {
return UIScreen.main.bounds.height
}
static var statusBarHeight: CGFloat {
return UIApplication.shared.statusBarFrame.size.height
}
}
그런 다음 다음을 수행 할 수 있습니다.
Screen.statusBarHeight
참고 URL : https://stackoverflow.com/questions/25973733/status-bar-height-in-swift
반응형
'IT story' 카테고리의 다른 글
Linux 기반 서버에서 ASP.Net 실행 (0) | 2020.09.06 |
---|---|
이름에 점이 포함 된 경우 JSON 개체 값을 얻는 방법은 무엇입니까? (0) | 2020.09.06 |
RxJava에서 Observable, Completable 및 Single의 차이점은 무엇입니까? (0) | 2020.09.06 |
NSOperationQueue가 모든 작업을 완료하면 알림 받기 (0) | 2020.09.06 |
.NET에는 List a에 List b의 모든 항목이 포함되어 있는지 확인할 수있는 방법이 있습니까? (0) | 2020.09.06 |