How do I change the font size of a UILabel in Swift?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Changing the font size of a UILabel is simple at the API level, but the right choice depends on whether you want a fixed design size, a custom typeface, or text that respects the user's accessibility settings. In production iOS code, you usually need to think about sizing, line wrapping, and Dynamic Type together rather than treating font size as one isolated property.
Set the Font Directly
The most direct way to change a label's font size is to assign a new UIFont to its font property.
This is the right choice when the design calls for a specific point size and you are creating the label in code. The moment you assign a new font, the label uses that size for all of its text unless you later replace it with an attributed string.
If you are using Interface Builder, the same change can be made in the Attributes Inspector, but the underlying idea is identical: UILabel renders whatever UIFont you set.
Use Custom Fonts Safely
If the design system uses a custom font family, load it by name and handle failure explicitly. A missing font registration should not crash the app silently.
This pattern is useful because the fallback keeps the screen readable while you diagnose a misconfigured font file or Info.plist entry.
Support Dynamic Type
For user-facing text, especially body copy, fixed sizes are often the wrong default. Dynamic Type lets the system scale text according to the user's accessibility and reading preferences.
This approach is usually better than hard-coding 17 or 20 for common text styles. It also reduces the maintenance burden because the system handles scaling rules consistently across the app.
If you need a custom font and Dynamic Type, scale the font with UIFontMetrics.
That keeps the brand font while still respecting accessibility settings.
Fit Text Within the Available Space
Changing font size is only part of the layout story. A large font can clip or truncate if the label is constrained too tightly. For labels that may grow, set the line count and layout constraints deliberately.
adjustsFontSizeToFitWidth exists, but it is usually best reserved for short, single-line labels where shrinking is acceptable.
For normal body text, wrapping is often better than aggressive shrinking.
Style Only Part of the Text
If you need multiple font sizes inside one label, use an attributed string instead of the plain font property.
That gives you fine-grained control without splitting the content into several labels.
Common Pitfalls
A common mistake is setting a large font size and then forgetting that the label still has one line and tight width constraints. The text looks fine in code review but truncates on smaller devices.
Another issue is using fixed point sizes for all text, including body content, and unintentionally ignoring accessibility. If the label contains important information, prefer a text style with Dynamic Type support.
Developers also sometimes use adjustsFontSizeToFitWidth as a general layout fix. It can hide constraint problems and make text too small to read.
Finally, if a custom font does not appear, verify that the font file is included in the target and registered correctly. The code may be fine while the project configuration is wrong.
Summary
- Set
label.fontwith aUIFontto change the size directly. - Use
UIFont.preferredFontandadjustsFontForContentSizeCategoryfor accessible text. - Scale custom fonts with
UIFontMetricsinstead of hard-coding one fixed size. - Handle wrapping and constraints so larger fonts do not clip or truncate unexpectedly.
- Use attributed strings when only part of the label needs a different size.

