0Pricing
SwiftUI Academy · Lezione

Sfondi e raggio degli angoli

Applicare colori, gradienti e angoli arrotondati.

Sfondi e raggio degli angoli è una lezione SwiftUI Academy gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento SwiftUI Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso SwiftUI Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Adding a Background

The background modifier paints behind a view. Drop in a color and the area the view occupies fills in, instantly turning plain text into a tile.

Text("Hello")
    .background(.blue)

Pad First, Then Color

A background hugs the content tightly. Add padding before the background so the color has comfortable space around the text inside.

Text("Pill")
    .padding()
    .background(.blue)

Readable Text on Color

Dark backgrounds need light text. Pair a colored background with foregroundStyle so your label stays crisp and easy to read.

Text("Tag")
    .padding()
    .background(.indigo)
    .foregroundStyle(.white)

Rounding the Corners

Sharp corners can feel harsh. The cornerRadius modifier softens them, clipping the view into a friendly rounded rectangle.

Text("Soft")
    .padding()
    .background(.blue)
    .cornerRadius(12)

Order Makes the Shape

Corner radius rounds whatever it follows, so place it after the background. Rounding before the color would clip the text, not the tile.

Background with a Shape

For more control, pass a shape to background. A RoundedRectangle fills and rounds in one step, the modern way to build cards.

Text("Card")
    .padding()
    .background(RoundedRectangle(cornerRadius: 16).fill(.teal))

Making a Circle

A large radius on a square view yields a circle. Combine an equal frame with clipShape using Circle for round avatars and icon badges.

Text("A")
    .frame(width: 60, height: 60)
    .background(.orange)
    .clipShape(Circle())

Gradients as Backgrounds

Backgrounds are not limited to flat colors. A LinearGradient adds depth, flowing smoothly from one color to another across the view.

Text("Glow")
    .padding()
    .background(LinearGradient(colors: [.pink, .orange], startPoint: .top, endPoint: .bottom))

Materials for Depth

SwiftUI ships translucent Material backgrounds that blur whatever sits behind them, giving cards a native, frosted-glass feel.

Text("Frosted")
    .padding()
    .background(.ultraThinMaterial)

Adding a Border

Pair a background with an overlay stroke to outline a card. The rounded rectangle border traces the same corners as the fill.

Text("Bordered")
    .padding()
    .overlay(RoundedRectangle(cornerRadius: 12).stroke(.gray))

Building a Real Card

Stack these tools and a card appears: padding for room, a background for color, and a corner radius to round it into a polished tile.

Text("Done")
    .padding()
    .background(.green)
    .cornerRadius(10)

Quick Check

Make sure the modifier order clicked for you.

Recap

Awesome! You can now style views with a background, round corners, add gradients, materials, and borders to build clean, reusable cards.

Domande Frequenti

La lezione «Sfondi e raggio degli angoli» è gratuita?

Sì — il testo completo di «Sfondi e raggio degli angoli» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso SwiftUI Academy, passa a CoddyKit PRO. Il corso SwiftUI Academy include 4 lezioni in totale.

Cosa imparerò in «Sfondi e raggio degli angoli»?

Applicare colori, gradienti e angoli arrotondati. Eserciti SwiftUI Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare SwiftUI Academy?

Non è richiesta alcuna esperienza precedente. SwiftUI Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.

Quanto tempo richiede la lezione «Sfondi e raggio degli angoli»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione SwiftUI Academy?

Sì. Ogni lezione SwiftUI Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Aggiungere padding alle view
  2. Dimensionare le view con frame
  3. Sfondi e raggio degli angoli
  4. Spacer e priorità di layout
← Torna a SwiftUI Academy