Tipo Dinâmico e Fontes Dimensionadas
Ofereça suporte a textos maiores sem quebrar o layout.
Tipo Dinâmico e Fontes Dimensionadas é 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.
What Is Dynamic Type?
Dynamic Type lets users pick their preferred text size system-wide. Your app should respect it, not force one fixed size. 🔤
Use Text Styles
Pick semantic text styles like .title or .body instead of fixed point sizes. These scale automatically with the user's setting.
Text("Welcome")
.font(.title)
Text("Details here")
.font(.body)Why Not Fixed Sizes
A hard-coded .font(.system(size: 17)) ignores the user's choice and stays small. Text styles adapt; fixed numbers don't.
Text("Stuck small")
.font(.system(size: 17))Scaling Custom Fonts
Have a brand font? Use .font(.custom:size:relativeTo:) so it still scales with a chosen text style.
Text("Brand")
.font(.custom("Avenir", size: 17, relativeTo: .body))The ScaledMetric Wrapper
Need a spacing or image size to grow with text? @ScaledMetric scales any number alongside Dynamic Type.
@ScaledMetric var iconSize = 24
Image(systemName: "star").frame(width: iconSize)Let Text Wrap
Big text needs room. Avoid lineLimit(1) on important labels, or long words will be cut off with an ellipsis.
Text(longTitle)
.lineLimit(2)Allow Tighter Fitting
When space is truly tight, minimumScaleFactor lets text shrink a little before truncating, keeping it readable.
Text(price)
.minimumScaleFactor(0.7)Preview Large Sizes
Use dynamicTypeSize in a preview to simulate the largest setting and catch broken layouts early.
#Preview {
ContentView()
.dynamicTypeSize(.accessibility3)
}Cap the Range If Needed
You can limit how far text scales with dynamicTypeSize(...), but cap sparingly so you don't shut out users who need more.
VStack { }
.dynamicTypeSize(...DynamicTypeSize.accessibility1)Stacks Over Fixed Frames
Prefer flexible stacks over rigid heights. A fixed frame can clip large text, while a stack grows to fit.
Test at Both Ends
Check your app at the smallest and the largest Dynamic Type sizes. If both read well, most users in between will too.
Quick Check
You want a custom brand font to grow with the user's text size. What do you use?
Recap
You made text adapt: choose semantic text styles, scale custom fonts and metrics, let text wrap, and test the largest size. 👍
Perguntas Frequentes
A aula “Tipo Dinâmico e Fontes Dimensionadas” é grátis?
Sim — o texto completo de “Tipo Dinâmico e Fontes Dimensionadas” é 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 “Tipo Dinâmico e Fontes Dimensionadas”?
Ofereça suporte a textos maiores sem quebrar o layout. 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 “Tipo Dinâmico e Fontes Dimensionadas”?
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
- VoiceOver e Rótulos de Acessibilidade
- Tipo Dinâmico e Fontes Dimensionadas
- Localizando Strings e Catálogos de Strings
- Adaptando-se aos Modos Claro e Escuro