0Pricing
SwiftUI Academy · Aula

Adicionando preenchimento ao redor das visualizações

Use preenchimento para criar espaço de respiro.

Adicionando preenchimento ao redor das visualizações é uma aula grátis de SwiftUI Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de SwiftUI Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de SwiftUI Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Why Views Feel Cramped

By default a SwiftUI view sits flush against its neighbors and the screen edge. Padding is the breathing room you add so content never feels squeezed.

Meet the padding Modifier

The padding modifier adds space on the outside of a view. Attach it like any other modifier and SwiftUI grows the view's footprint to make room.

Text("Hello")
    .padding()

The Default Amount

Calling padding() with no value uses a system default that adapts to the platform, usually around 16 points. It is a safe, consistent starting point.

Setting an Exact Amount

Pass a number to control the gap precisely. Here padding(40) adds 40 points of space on every side of the text.

Text("Spaced")
    .padding(40)

Padding One Edge

You can target a single edge instead of all four. This adds 30 points only on top, leaving the other sides untouched.

Text("Top gap")
    .padding(.top, 30)

Horizontal and Vertical

The .horizontal and .vertical edge sets are handy shortcuts. This pads the left and right sides at once with one clean call.

Text("Sides")
    .padding(.horizontal, 24)

Combining Edge Sets

Stack two padding calls to mix amounts per direction. Here the view gets wide horizontal margins and a smaller vertical gap.

Text("Mixed")
    .padding(.horizontal, 32)
    .padding(.vertical, 8)

Order Matters

Modifiers apply outward in order, so where you place padding changes the result. Padding before a background pushes the color outward with the content.

Text("Hi")
    .padding()
    .background(.yellow)

Padding Then Background

Swap the order and the difference is clear: a background applied first, then padding, leaves the color tight to the text with empty space around it.

Text("Hi")
    .background(.yellow)
    .padding()

Padding on Containers

Padding works on stacks and any view, not just text. Wrap a VStack and pad it to push the whole group inward from the screen edges.

VStack {
    Text("Line one")
    Text("Line two")
}
.padding()

Padding vs Margins

SwiftUI has no separate margin concept. Padding is your single tool for spacing, and chaining it gives you full control over every edge.

Quick Check

Test your grip on the padding modifier.

Recap

Nice work! You learned that padding adds breathing room outside a view, with defaults, exact amounts, specific edges, and an order that shapes backgrounds.

Perguntas Frequentes

A aula “Adicionando preenchimento ao redor das visualizações” é grátis?

Sim — o texto completo de “Adicionando preenchimento ao redor das visualizações” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de SwiftUI Academy, atualize para CoddyKit PRO. O curso de SwiftUI Academy inclui 4 aulas no total.

O que vou aprender em “Adicionando preenchimento ao redor das visualizações”?

Use preenchimento para criar espaço de respiro. Você pratica SwiftUI Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar SwiftUI Academy?

Nenhuma experiência prévia é necessária. SwiftUI Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.

Quanto tempo leva a aula “Adicionando preenchimento ao redor das visualizações”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de SwiftUI Academy?

Sim. Cada aula de SwiftUI Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Adicionando preenchimento ao redor das visualizações
  2. Dimensionando visualizações com frame
  3. Planos de fundo e raio dos cantos
  4. Spacer e prioridade de layout
← Voltar para SwiftUI Academy