0Pricing
SwiftUI Academy · レッスン

ビューを縦方向に積み重ねる

VStack でビューを上から下へまとめます。

「ビューを縦方向に積み重ねる」はCoddyKit上の無料SwiftUI Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSwiftUI Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 SwiftUI Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why You Need Stacks

A SwiftUI body can return only one view. To show several views together, you wrap them in a container that arranges them for you. 📦

Meet VStack

A VStack stacks its child views vertically, top to bottom. It is your go-to container for column-style layouts like a title above a subtitle.

Your First VStack

Place views inside the VStack braces and they appear in order, each on its own line. The first child sits at the top.

VStack {
    Text("Hello")
    Text("World")
}

Order Matters

Children render in the exact order you write them. Swap two lines of code and the views swap places on screen. Top of the code is top of the column.

Centered by Default

By default a VStack centers its children horizontally and shrinks to fit its content, like a tidy little column hugging its views.

Mixing View Types

A VStack does not care what kind of views it holds. You can freely mix a Text, an Image, and a Button in the same vertical stack.

VStack {
    Image(systemName: "star")
    Text("Favorite")
}

How Many Views Fit?

A stack can hold up to ten direct children at once. That is plenty for most screens, and you can always nest stacks for more.

Nesting Stacks

You can put a VStack inside another VStack to build richer layouts. Nesting lets you group related views so they move together.

VStack {
    Text("Title")
    VStack {
        Text("Line 1")
        Text("Line 2")
    }
}

Stacks Are Views Too

A VStack is itself a view, so you can apply modifiers like padding or background to the whole stack at once. The group acts as one unit.

Returning a VStack from body

Since body needs a single view, returning a VStack is the classic way to show many views. The stack becomes that one returned view.

var body: some View {
    VStack {
        Text("One")
        Text("Two")
    }
}

When to Reach for VStack

Use a VStack whenever items should read top to bottom: a heading over body text, a label over a value, or a form laid out in rows.

Quick Check

Let's make sure VStack ordering is clear.

Recap: Vertical Stacking

Nice work! A VStack arranges views top to bottom in code order, centers them by default, and acts as one view you can style or nest. 🎉

よくある質問

「ビューを縦方向に積み重ねる」レッスンは無料ですか?

はい。「ビューを縦方向に積み重ねる」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、SwiftUI Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 SwiftUI Academyコースには全4レッスンが含まれています。

「ビューを縦方向に積み重ねる」で何を学びますか?

VStack でビューを上から下へまとめます。 ブラウザで直接実行するハンズオンコードでSwiftUI Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

SwiftUI Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのSwiftUI Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「ビューを縦方向に積み重ねる」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このSwiftUI Academyレッスンでコードを書いて実行できますか?

はい。すべてのSwiftUI Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ビューを縦方向に積み重ねる
  2. HStack で行を作る
  3. ZStack で重ねる
  4. Stack の間隔と配置
← SwiftUI Academyに戻る