0Pricing
SwiftUI Academy · บทเรียน

การไล่ระดับสีเชิงเส้น รัศมี และเชิงมุม

เติมสีให้ View ด้วยการเปลี่ยนผ่านของสีอย่างราบรื่น

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

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

What Is a Gradient?

A gradient blends smoothly between two or more colors. It adds depth and polish that a flat fill cannot. 🌈

Gradients Are Views Too

Just like Color, a LinearGradient is a view. You can place it directly or use it to fill a shape or background.

Your First LinearGradient

A LinearGradient flows colors along a straight line. Give it colors plus a start and end point to set the direction.

LinearGradient(
    colors: [.blue, .purple],
    startPoint: .top,
    endPoint: .bottom
)

Choosing Start & End Points

Points like .topLeading and .bottomTrailing aim the gradient diagonally. Swap them to change the angle of the blend.

startPoint: .topLeading
endPoint: .bottomTrailing

More Than Two Colors

Pass several colors and the gradient spreads them evenly across its length. Great for sunset-style backgrounds.

LinearGradient(
    colors: [.orange, .pink, .purple],
    startPoint: .leading,
    endPoint: .trailing
)

RadialGradient Glows Outward

A RadialGradient radiates from a center point outward in a circle. It is perfect for spotlights and soft glows.

RadialGradient(
    colors: [.yellow, .red],
    center: .center,
    startRadius: 5,
    endRadius: 120
)

Tuning the Radius

The startRadius and endRadius control how tight or wide the glow spreads. Bigger gaps mean smoother, slower fades.

AngularGradient Sweeps Around

An AngularGradient wraps colors around a center, like a color wheel. It creates a cool conical, swirling effect.

AngularGradient(
    colors: [.red, .green, .blue, .red],
    center: .center
)

Gradient as a Background

Attach a gradient with the background modifier to brighten any view behind your content. Instant visual lift.

Text("Hi")
    .padding()
    .background(LinearGradient(
        colors: [.blue, .cyan],
        startPoint: .top, endPoint: .bottom))

Shorthand Gradients

For a quick blend, call .gradient on any color. SwiftUI builds a subtle top-to-bottom gradient for you instantly.

Circle()
    .fill(Color.blue.gradient)

Pick the Right Gradient

Use linear for directional fades, radial for glows, and angular for wheels. Each gives a different mood to your UI. 🎨

Quick Check

Which gradient sweeps its colors around a center point?

Recap: Gradients

You now blend colors three ways: linear along a line, radial from a center, and angular around a wheel. Beautiful work!

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

บทเรียน “การไล่ระดับสีเชิงเส้น รัศมี และเชิงมุม” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “การไล่ระดับสีเชิงเส้น รัศมี และเชิงมุม”

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

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

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

บทเรียน “การไล่ระดับสีเชิงเส้น รัศมี และเชิงมุม” ใช้เวลานานแค่ไหน

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

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

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

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

  1. ชนิด Color และสีจากทรัพยากร
  2. การไล่ระดับสีเชิงเส้น รัศมี และเชิงมุม
  3. รูปร่างในตัว
  4. เส้นขอบ การเติมสี และ overlay
← กลับไปที่ SwiftUI Academy