100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Swift

Text and Typography in SwiftUI

How the Text view handles fonts, Dynamic Type, styling, and localization to produce accessible, readable typography.

Building UIs with SwiftUIBeginner7 min readJul 8, 2026
Analogies

Text and Typography in SwiftUI

Text is SwiftUI's view for displaying strings, and it's one of the most frequently used views in any app. Beyond simply rendering characters, Text integrates with Apple's typography system: Dynamic Type scaling for accessibility, semantic font styles like .headline and .body that automatically adapt across devices, and built-in support for localized and interpolated strings, including automatically formatting dates, numbers, and measurements passed directly into a Text initializer.

🏏

Cricket analogy: A stadium's digital scoreboard doesn't just print raw characters — it auto-formats a bowler's economy rate to two decimals and localizes player names for the home broadcast, the same way SwiftUI's Text auto-formats dates, numbers, and measurements and adapts to Dynamic Type for accessibility.

Fonts and Semantic Text Styles

Rather than hardcoding a point size like .font(.system(size: 17)), SwiftUI encourages semantic text styles — .largeTitle, .title, .title2, .headline, .body, .callout, .caption — via .font(.headline). These map to Apple's Dynamic Type system, meaning the actual rendered size automatically scales when a user increases their preferred text size in Settings for accessibility. Hardcoding fixed point sizes bypasses this system entirely, making text unreadable for users who rely on larger accessibility text sizes.

🏏

Cricket analogy: A scoreboard that hardcodes the batsman's name at a fixed tiny font size ignores fans in the back stands who need it bigger; using a semantic style like .headline instead automatically scales for every viewer's needs, the way Dynamic Type respects a user's accessibility text-size setting.

swift
struct ArticleHeader: View {
    let title: String
    let publishedDate: Date
    let readingMinutes: Int

    var body: some View {
        VStack(alignment: .leading, spacing: 6) {
            Text(title)
                .font(.title.bold())
                .foregroundStyle(.primary)

            Text("Published \(publishedDate, style: .date) \u{2022} \(readingMinutes) min read")
                .font(.subheadline)
                .foregroundStyle(.secondary)
        }
    }
}

Styling, Truncation, and Multi-Style Text

Modifiers like .bold(), .italic(), .underline(), .strikethrough(), and .foregroundStyle() compose with Text, and Text values can even be concatenated with + to mix styles within a single line, such as a bold name followed by regular-weight body copy. For long content, .lineLimit() caps the number of visible lines and .truncationMode() controls where an ellipsis appears, while .multilineTextAlignment() controls alignment when text wraps across multiple lines — a distinct concept from the containing stack's own alignment.

🏏

Cricket analogy: A player profile card mixes a bold player name with regular-weight team info concatenated in one line using +, while a long bio gets .lineLimit(3) with a trailing ellipsis and .multilineTextAlignment(.leading) for how the wrapped lines align.

Text automatically formats many value types passed via string interpolation — Text("\(date, style: .relative)") renders as '2 hours ago' style relative dates, and Text(price, format: .currency(code: "USD")) renders locale-correct currency formatting, without manual DateFormatter or NumberFormatter boilerplate.

Overriding text color with .foregroundStyle(.black) instead of .primary breaks automatic light/dark mode adaptation — always prefer semantic colors like .primary and .secondary unless a fixed color is truly intentional.

  • Text is SwiftUI's view for rendering strings, with deep integration into Apple's typography and accessibility systems.
  • Semantic font styles like .headline and .body scale automatically with the user's Dynamic Type accessibility setting.
  • Hardcoded fixed-size fonts bypass Dynamic Type scaling and hurt accessibility.
  • Text values can be concatenated with + to mix styles (e.g. bold plus regular) within one line.
  • Text auto-formats interpolated dates, numbers, and currency without manual formatter boilerplate.
  • Semantic colors like .primary/.secondary should be preferred over fixed colors to support light/dark mode.

Practice what you learned

Was this page helpful?

Topics covered

#Swift#IOSWithSwiftUIStudyNotes#MobileDevelopment#TextAndTypographyInSwiftUI#Text#Typography#SwiftUI#Fonts#StudyNotes#SkillVeris