HStack で行を作る
ビューを水平方向に横並びで配置します。
「HStack で行を作る」はCoddyKit上の無料SwiftUI Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSwiftUI Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 SwiftUI Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Going Horizontal
Sometimes views belong side by side, not stacked down. For that you reach for the horizontal sibling of VStack. ➡️
Meet HStack
An HStack arranges its children horizontally, left to right. It is perfect for rows like an icon next to a label.
Your First HStack
Put views inside the HStack braces and they line up across the screen in the order you wrote them.
HStack {
Text("Left")
Text("Right")
}Left to Right Order
In an HStack the first child sits on the leading edge and later children follow toward the trailing edge. Code order is left-to-right order.
Icon Plus Label
A classic HStack pairs an Image with a Text so an icon and its caption stay on one line, like a row in a settings screen.
HStack {
Image(systemName: "bell")
Text("Alerts")
}Centered Vertically
By default an HStack aligns its children to the vertical center, so a tall image and short text line up neatly along their middles.
HStack Hugs Its Content
Just like VStack, an HStack shrinks to fit its children rather than filling the whole width. It takes only the space it needs.
Combining HStack and VStack
Nest an HStack inside a VStack to build a card: a title row on top and a detail row below. Mixing both directions builds real layouts.
VStack {
Text("Title")
HStack {
Text("A")
Text("B")
}
}HStack Is a View
An HStack is a view too, so modifiers like padding or background apply to the entire row at once, treating it as a single block.
Mixed Content Rows
An HStack happily holds different view types together, like a number, a label, and a button all sharing one horizontal line.
HStack {
Text("42")
Button("Add") { }
}When to Reach for HStack
Use an HStack whenever items read left to right: a label and value, a toolbar of buttons, or an avatar beside a name.
Quick Check
Let's confirm how HStack lays things out.
Recap: Horizontal Rows
Great progress! An HStack lines views up left to right, centers them vertically, and pairs beautifully with VStack to build cards and rows. 🙌
よくある質問
「HStack で行を作る」レッスンは無料ですか?
はい。「HStack で行を作る」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、SwiftUI Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 SwiftUI Academyコースには全4レッスンが含まれています。
「HStack で行を作る」で何を学びますか?
ビューを水平方向に横並びで配置します。 ブラウザで直接実行するハンズオンコードでSwiftUI Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
SwiftUI Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSwiftUI Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「HStack で行を作る」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSwiftUI Academyレッスンでコードを書いて実行できますか?
はい。すべてのSwiftUI Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- ビューを縦方向に積み重ねる
- HStack で行を作る
- ZStack で重ねる
- Stack の間隔と配置