แบบอักษร น้ำหนัก และสี
ตกแต่งข้อความด้วย font, fontWeight และ foregroundStyle
แบบอักษร น้ำหนัก และสี เป็นบทเรียน SwiftUI Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน SwiftUI Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Styling Starts Here
A plain Text view shows words, but real apps style them. In this lesson you will set font, weight, and color to make text feel intentional. 🎨
The font Modifier
The font modifier picks a text style. Apple ships semantic sizes like title, headline, and body that adapt to the user automatically.
Text("Welcome")
.font(.title)Semantic Font Styles
Prefer semantic styles over fixed point sizes. Names like .largeTitle and .caption scale with the device and the user accessibility settings.
Text("Big").font(.largeTitle)
Text("Small").font(.caption)Custom Point Sizes
Need an exact size? Pass .system(size:) with a number. It is handy for logos, but semantic styles are better for body text.
Text("Logo")
.font(.system(size: 40))Adding Weight
The fontWeight modifier sets how thick the strokes look. Try .bold for emphasis or .light for a softer, airier feel.
Text("Strong")
.fontWeight(.bold)Weight Inside font
You can also bake the weight right into the font call. This keeps related styling in one tidy place.
Text("Heavy")
.font(.title.weight(.heavy))Coloring Text
Use foregroundStyle to color text. Pass a Color like .red or a brand color, and the words pick up that tint instantly.
Text("Alert")
.foregroundStyle(.red)Semantic Colors
Reach for semantic colors like .primary and .secondary. They adapt to light and dark mode so your text stays readable everywhere.
Text("Hint")
.foregroundStyle(.secondary)Italic and Bold Shortcuts
SwiftUI offers quick toggles: .bold() and .italic(). They read cleanly and skip the longer modifier names.
Text("Note")
.bold()
.italic()Chaining Modifiers
Modifiers stack top to bottom. Combine font, weight, and color on one Text to shape its full look in a single chain.
Text("Title")
.font(.title)
.bold()
.foregroundStyle(.blue)Order Can Matter
Most text modifiers commute, but order matters once layout enters. Keep styling first, then add padding or background later.
Quick Check
Which modifier sets the text color?
Lesson Recap
You styled text with font, fontWeight, and foregroundStyle. Lean on semantic styles and colors so your UI adapts beautifully. ✨
คำถามที่พบบ่อย
บทเรียน “แบบอักษร น้ำหนัก และสี” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “แบบอักษร น้ำหนัก และสี” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส SwiftUI Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส SwiftUI Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “แบบอักษร น้ำหนัก และสี”
ตกแต่งข้อความด้วย font, fontWeight และ foregroundStyle คุณปฏิบัติ SwiftUI Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน SwiftUI Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน SwiftUI Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “แบบอักษร น้ำหนัก และสี” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน SwiftUI Academy นี้ได้ไหม
ได้ บทเรียน SwiftUI Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- แบบอักษร น้ำหนัก และสี
- ข้อความหลายบรรทัดและการจัดแนว
- การโหลดรูปภาพจากทรัพยากร
- การใช้ SF Symbols