Fix: Custom System Font Size Not Working in SwiftUI

Written by

in

Quick answer: SF Pro fonts are system fonts and cannot be loaded by name with .font(.custom(...)). Use .font(.system(size: 21, weight: .medium)) for explicit sizing or .font(.system(size: 21, weight: .medium, design: .default)) to preserve dynamic type scaling.

Why this happens

Apple’s San Francisco (SF Pro) fonts are system fonts, not bundled font files you can reference by PostScript name. When you call .font(.custom("SFProText-Light", size: 21)), SwiftUI looks for a font file with that exact name in your app bundle or the system font registry. Since SF Pro isn’t installed as a named font face, the call falls back to the default system font at the default size — silently ignoring your size and weight.

The same applies to the older SFUIDisplay-* and SFUIText-* names used in early iOS versions. They were never public font identifiers. Font Book shows SFProText-Light as a display name, not the programmatic name SwiftUI expects.

How to fix it

1. Use .system(size:weight:design:) for explicit sizing

The direct replacement is the .system factory method. It gives you exact point size control while keeping all system-font behaviors (dynamic type, trait collections, automatic weight fallbacks).

Text("Primary action")
    .font(.system(size: 21, weight: .medium, design: .default))
  • size: CGFloat — absolute point size.
  • weight: Font.Weight — .ultraLight … .black (.medium matches your original intent).
  • design: Font.Design — .default (proportional), .serif, .rounded, .monospaced.

2. Preserve Dynamic Type with relative sizing

Hard-coding size: 21 opts out of Dynamic Type. If you want the look of 21 pt at the default text size but still scale with the user’s accessibility setting, start from a text style and scale it:

// 21 pt at default, scales with accessibility
.font(.system(.title3, design: .default).weight(.medium))

// Or scale a specific point size relative to body
.font(.system(size: 21, weight: .medium, design: .default)
      .relativeTo(.body))

.relativeTo(.body) (iOS 17+) tells SwiftUI: “treat 21 pt as the size at the default body scale, then grow/shrink proportionally.”

3. Create a reusable extension (optional)

If you use this exact combination across the app, wrap it once:

extension Font {
    static var primaryButton: Font {
        .system(size: 21, weight: .medium, design: .default)
    }
}

// Usage
Text("Submit")
    .font(.primaryButton)

4. When you do need .custom()

Only use .custom(name:size:) for custom fonts you ship in the app bundle (added to Info.plist under UIAppFonts). Example:

// Custom font file "Inter-VariableFont_opsz,wght.ttf" added to target
.font(.custom("Inter", size: 21, relativeTo: .body))

How to prevent it

  • Never guess PostScript names for SF Pro — they are private.
  • Default to .system(...) for any San Francisco variant.
  • Use text styles (.title, .body, .caption, etc.) whenever possible; they auto-scale.
  • If you need a fixed optical size, combine .system(size:weight:design:) with .relativeTo(.body).
  • Add custom fonts to the Xcode target’s Copy Bundle Resources and declare them in Info.plist.

FAQ

Why did HelveticaNeue-UltraLight work in my test?

Helvetica Neue is installed on iOS as a named font face, so .custom("HelveticaNeue-UltraLight", size: 20) resolves. SF Pro is not exposed the same way.

Can I use .font(.system(size: 21)) without weight and design?

Yes. The single-argument .system(size:) defaults to .regular weight and .default design. It’s equivalent to .system(size: 21, weight: .regular, design: .default).

Does .system(size:) respect the user’s Bold Text accessibility setting?

Only if you also specify a weight (.medium, .bold, etc.) or start from a text style. A plain .system(size: 21) ignores the Bold Text toggle; the glyphs stay regular weight.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.