GeometryReader
を使用します。
公式ドキュメント: https://developer.apple.com/documentation/swiftui/geometryreader
struct ContentView: View {
var body: some View {
GeometryReader { proxy in
VStack(alignment: .leading) {
Text(String("\(proxy.size)")) // 親ビューのサイズ
Text(String("\(safeArea())")) // セーフエリア
}
}
}
}
以下は一番上の親(ContentView)で iPhone 13 で試した時の表示です。iPhone13 は画面サイズ 6.1 inch(390×844)、そのうち縦のセーフエリアが top: 47、bottom: 34 を占めるので、763という結果になっています。
