Texto multilinha e alinhamento
Controle os limites de linha, a quebra de linha e o alinhamento do texto.
Texto multilinha e alinhamento é uma aula grátis de SwiftUI Academy no CoddyKit. Esta é a aula 2 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.
When Text Gets Long
Short labels fit on one line, but paragraphs wrap. This lesson shows how to control wrapping, line limits, and alignment for longer text. 📝
Text Wraps by Default
SwiftUI wraps long text onto multiple lines automatically when there is room. You usually do not need to do anything for basic wrapping.
Text("A fairly long sentence that will wrap onto more than one line.")Limiting Lines
The lineLimit modifier caps how many lines show. Extra text is truncated with an ellipsis, which is great for previews and cards.
Text(longBio)
.lineLimit(2)Truncation Mode
Control where the cut happens with truncationMode. Choose .tail, .head, or .middle depending on which part matters most.
Text(path)
.lineLimit(1)
.truncationMode(.middle)Aligning Multiline Text
Use multilineTextAlignment to align wrapped lines left, center, or trailing. It only affects text that spans more than one line.
Text(quote)
.multilineTextAlignment(.center)Frame Versus Text Alignment
Remember the difference: frame alignment positions the whole block, while multilineTextAlignment arranges lines inside that block.
Centering a Block
To center a block and its lines, give it a wide frame and a center text alignment together. Both work as a pair.
Text(notice)
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)Line Spacing
Add breathing room between lines with lineSpacing. A few extra points often makes dense paragraphs much easier to read.
Text(article)
.lineSpacing(6)Allowing Tight Layout
When space is tight, minimumScaleFactor lets text shrink instead of truncating, keeping the whole message visible.
Text(headline)
.lineLimit(1)
.minimumScaleFactor(0.7)Fixed Size to Avoid Clipping
If wrapping text gets squeezed, fixedSize tells it to keep its ideal height so nothing gets unexpectedly clipped.
Text(message)
.fixedSize(horizontal: false, vertical: true)Putting It Together
Combine lineLimit, alignment, and spacing to craft readable cards. Small tweaks add up to a polished reading experience.
Quick Check
Which modifier aligns wrapped lines of text?
Lesson Recap
You shaped long text with lineLimit, truncation, alignment, and spacing. These tools keep paragraphs tidy and easy to read. 👍
Perguntas Frequentes
A aula “Texto multilinha e alinhamento” é grátis?
Sim — o texto completo de “Texto multilinha e alinhamento” é 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 “Texto multilinha e alinhamento”?
Controle os limites de linha, a quebra de linha e o alinhamento do texto. 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 2 de 4.
Quanto tempo leva a aula “Texto multilinha e alinhamento”?
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
- Fontes, espessura e cor
- Texto multilinha e alinhamento
- Carregando imagens dos recursos
- Usando SF Symbols