How do I set bold and italic on UILabel of iPhone/iPad?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
To make UILabel text bold or italic on iPhone or iPad, you either assign a font directly or use an attributed string. The simple font approach works when the whole label should share one style, while attributed strings are the right choice when only part of the text needs bold or italic formatting.
The main technical detail is that not every font family has both bold and italic variants. That is why trait-based font conversion or attributed text is often more reliable than hard-coding one font name and hoping all variants exist.
Set the Entire Label Font
If the whole label should be bold, assign a bold system font:
For italic text, use the italic system font:
This is the easiest solution when the full label uses one style only.
Combine Bold and Italic with a Font Descriptor
If you want both bold and italic traits together, use a font descriptor:
This asks the system font family for the combined traits instead of guessing a specific face name.
Style Only Part of the Text with NSAttributedString
If only one word or range should be bold or italic, use attributed text:
This is the usual answer when the label contains mixed formatting.
Use Custom Fonts Carefully
For custom fonts, you need the actual font names that correspond to regular, bold, or italic variants:
This works only if that font face exists in the app bundle or system. Custom font naming is family-specific, so system-font examples do not always translate directly.
Decide Between text and attributedText
A useful rule is:
- use
fontwhen the entire label shares one style - use
attributedTextwhen styles vary within one label
That keeps the implementation simple and avoids unnecessary attributed-string complexity for plain cases.
Test the Actual Font Combination
Even when the code compiles, the visual result depends on the available font faces. It is worth checking the label on device or simulator to confirm that the chosen family really has the bold, italic, or bold-italic variant you expect.
This is especially relevant for custom fonts, where naming and trait support vary much more than with system fonts.
If the font is wrong, the label may silently fall back to a nearby face instead of the exact style you wanted.
Common Pitfalls
- Expecting
UILabelto combine bold and italic automatically without a suitable font face. - Hard-coding a custom font name that does not actually exist.
- Using
fontwhen only part of the label should be styled. - Replacing
attributedTextlater withtextand losing formatting. - Assuming every font family supports the same trait combinations.
Summary
- Use
UIFont.boldSystemFontorUIFont.italicSystemFontwhen the whole label uses one style. - Use a font descriptor when you want bold and italic traits together.
- Use
NSAttributedStringwhen only part of the label should be styled. - Custom fonts require real bold and italic face names.
- Choose the simplest approach that matches how much of the label needs formatting.
Related reading
- How do I set the height of tableHeaderView UITableView with autolayout?
- How do I set the size of a SF Symbol in SwiftUI?
- How do I set up a simple delegate to communicate between two view controllers?
- How do I set up IntelliJ IDEA for Android applications?
- How do I set up IntelliJ IDEA for Android applications?
- How do I shake an Android device within the Android emulator to bring up the dev menu to debug my React Native app
- How do I show the number keyboard on an EditText in android?
- How do I show/hide a UIBarButtonItem?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.