SwiftUI Academy · บทเรียน

ส่วนและรูปแบบรายการ

จัดกลุ่มแถวด้วยส่วนต่าง ๆ และเลือกรูปแบบรายการ

บทเรียน 4 จาก 413 ขั้นตอน

ส่วนและรูปแบบรายการ เป็นบทเรียน SwiftUI Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน SwiftUI Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Grouping with Sections

A long list reads better when split into chunks. Section groups related rows under a shared heading. 🗂️

List {
    Section("Fruits") {
        Text("Apple")
    }
}

Headers and Footers

A Section can show a header above its rows and a footer below, great for titles and helper text.

Section {
    Text("Wi-Fi")
} header: {
    Text("Network")
} footer: {
    Text("Tap to connect")
}

Multiple Sections

Stack several Section blocks in one List to organize a busy screen into clear, labeled groups that are easy to scan.

List {
    Section("On") { Text("Item A") }
    Section("Off") { Text("Item B") }
}

Sections With ForEach

Combine Section with ForEach to build grouped, data-driven lists, like contacts sorted by letter.

Section("A") {
    ForEach(aNames, id: \.self) { Text($0) }
}

Meet List Styles

The listStyle modifier changes a list's whole look, from grouped cards to plain edge-to-edge rows.

List { Text("Row") }
    .listStyle(.insetGrouped)

The Inset Grouped Look

insetGrouped is the default rounded-card style you see in Settings, with spacing around each section.

.listStyle(.insetGrouped)

The Plain Style

The plain style removes the card insets for full-width, edge-to-edge rows, ideal for feeds and chat-like screens.

.listStyle(.plain)

The Grouped Style

The grouped style gives boxed sections without the rounded inset corners, a classic full-width table look.

.listStyle(.grouped)

Styling Section Headers

You can restyle a header with modifiers, changing its font, color, or case to match your design.

header: {
    Text("Network").font(.headline)
}

Collapsible Sections

A header can act as a control too, letting you build expandable sections that show or hide their rows.

Pick the Right Style

Choose a style that fits the screen: insetGrouped for settings, plain for content feeds. The data stays the same. ✨

Quick Check

Match each concept to its job.

Recap

You learned Section and listStyle: group rows into labeled chunks and switch looks like insetGrouped or plain. 🎉

เริ่มต้นได้ฟรี

เรียนรู้ Swift ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
30
บทเรียน
120

คำถามที่พบบ่อย

บทเรียน “ส่วนและรูปแบบรายการ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ส่วนและรูปแบบรายการ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส SwiftUI Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ส่วนและรูปแบบรายการ”

จัดกลุ่มแถวด้วยส่วนต่าง ๆ และเลือกรูปแบบรายการ คุณปฏิบัติ SwiftUI Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน SwiftUI Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน SwiftUI Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “ส่วนและรูปแบบรายการ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน SwiftUI Academy นี้ได้ไหม

ได้ บทเรียน SwiftUI Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การสร้างรายการแบบคงที่
  2. การวนซ้ำด้วย ForEach
  3. Identifiable และ ID ที่เสถียร
  4. ส่วนและรูปแบบรายการ
← กลับไปที่ SwiftUI Academy