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のVStack / HStack / ZStack について簡単にまとめてみました (初心者向け🔰)

Posted at

SwiftUIでUIを作るときに絶対に使うのが VStack / HStack / ZStack
これらは「どう並べるか(レイアウト)」を決める大事なパーツです。

この記事では、初心者の方に向けて、3つのStackの使い方をシンプルに紹介します!


1 - VStack(縦に並べる)

VはVertical(垂直)の略。縦にUIを並べたいときに使います。

ポイント

  • 上から下にUIが並ぶ
  • spacingで間隔も調整可能

Screenshot 2025-05-26 at 17.25.38.png


2 - HStack(横に並べる)
HはHorizontal(水平)の略。横にUIを並べたいときに使います。
左から右にUIが並ぶ

ポイント

  • spacing
  • alignment も使える

Screenshot 2025-05-26 at 17.31.18.png


3 - ZStack(重ねて表示)
ZはZ軸(奥行き)のこと。UIを重ねて表示するときに使います。

Screenshot 2025-05-26 at 17.32.47.png


組み合わせて使ってみた

Screenshot 2025-05-26 at 17.34.14.png


まとめ

VStack

  • 縦に並べる
  • リストや縦レイアウトの画面

HStack

  • 横に並べる
  • アイコンと文字を横並びにするとき

ZStack

  • 重ねて表示
  • 背景画像+テキストなどの重ね表示

最後に
VStack、HStack、ZStackを覚えるだけで、SwiftUIのレイアウトはぐっと自由になります!
ぜひ自分で色々試してみてください!

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?