0Pricing
SwiftUI Academy · Pelajaran

ScrollView Horizontal & Vertikal

Gulir konten apa pun ke arah mana saja.

ScrollView Horizontal & Vertikal adalah pelajaran SwiftUI Academy gratis di CoddyKit. Ini adalah pelajaran 1 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar SwiftUI Academy, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus SwiftUI Academy mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

Beyond One Screen

Sometimes your content is taller than the screen. A ScrollView lets users glide past the edges to see it all. 📜

ScrollView {
    Text("Lots of content here")
}

Vertical by Default

A plain ScrollView scrolls up and down. Wrap a tall VStack inside and everything becomes swipeable.

ScrollView {
    VStack {
        Text("Top")
        Text("Bottom")
    }
}

Going Horizontal

Pass .horizontal as the axis and your content scrolls left and right instead, great for image carousels.

ScrollView(.horizontal) {
    HStack {
        Text("One")
        Text("Two")
    }
}

Pick Your Axis

The first argument is the axis: use .vertical, .horizontal, or even both for free, two-way scrolling.

ScrollView([.horizontal, .vertical]) {
    BigContent()
}

Hiding the Indicator

Set showsIndicators to false to hide the little scroll bar for a cleaner, more designed look.

ScrollView(.horizontal, showsIndicators: false) {
    HStack { /* cards */ }
}

Content Sizes Itself

A ScrollView only scrolls when its content is bigger than the visible area. Short content just sits still.

Pair with a Stack

Always put a VStack or HStack inside, since a ScrollView holds one child and the stack lines the rest up.

ScrollView {
    VStack(spacing: 16) {
        Card()
        Card()
    }
}

Free-form vs List

Reach for a ScrollView when you want full layout freedom; a List adds rows and separators for you.

Add Some Padding

Give inner content padding so it does not hug the screen edges as users scroll past it.

ScrollView {
    VStack { /* content */ }
        .padding()
}

Carousels Made Easy

A horizontal ScrollView of cards is the classic recipe for a swipeable carousel of photos or products.

ScrollView(.horizontal) {
    HStack {
        ForEach(items) { Card($0) }
    }
}

Smooth and Native

Scrolling feels buttery because ScrollView uses the same engine as the rest of iOS. It just works. ✨

Quick Check

Think about which direction you want to move.

Recap

You learned that a ScrollView reveals overflowing content, scrolls vertically by default, and goes horizontal with an axis. 🎉

Pertanyaan yang Sering Diajukan

Apakah pelajaran “ScrollView Horizontal & Vertikal” gratis?

Ya — teks lengkap “ScrollView Horizontal & Vertikal” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus SwiftUI Academy, upgrade ke CoddyKit PRO. Kursus SwiftUI Academy mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “ScrollView Horizontal & Vertikal”?

Gulir konten apa pun ke arah mana saja. Kamu berlatih SwiftUI Academy dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai SwiftUI Academy?

Tidak diperlukan pengalaman sebelumnya. SwiftUI Academy di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 1 dari 4.

Berapa lama pelajaran “ScrollView Horizontal & Vertikal” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran SwiftUI Academy ini?

Ya. Setiap pelajaran SwiftUI Academy menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. ScrollView Horizontal & Vertikal
  2. LazyVStack & LazyHStack
  3. Grid Adaptif dengan LazyVGrid
  4. Pembaca ScrollView & Anchor
← Kembali ke SwiftUI Academy