0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SwiftUI Viewの大きさ取得方法

Posted at

SwiftUIでViewの大きさ取得方法

.swift
var body: some View {
    GeometryReader { geometry in
        VStack {
            Text("幅: \(geometry.size.width)")
            Text("高さ: \(geometry.size.height)")
        }
        .frame(width: geometry.size.width, height: geometry.size.height)
        .background(Color.blue)
    }
    .frame(height: 200)
    .frame(width: 300)
}

Simulator Screenshot - iPhone 16 Pro - 2024-11-24 at 15.44.45.png

GeometryReaderを使用するとViewの大きさを取得することができます。

geometry.size.width 横幅
geometry.size.height 高さ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?