画面の幅(width)と高さ(height)を取得するには、UIScreen.main.bounds プロパティが持つ widthとheightを参照します。
UIScreen.main.bounds.width // width
UIScreen.main.bounds.height // height
目次
サンプルコード
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Text("Width: \(Int(UIScreen.main.bounds.width))")
Text("Width: \(Int(UIScreen.main.bounds.height))")
}
}
}
#Preview{
ContentView()
}
![](https://seeds-digital.com/wp-content/uploads/2023/11/fa442c265579582c3ffd2f835d300cb5-1024x507.png)
Comment