UILabel
iOS development
Swift programming
text styling
iPhone/iPad customization

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.

Browse interview questions

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:

swift
label.font = UIFont.boldSystemFont(ofSize: 17)

For italic text, use the italic system font:

swift
label.font = UIFont.italicSystemFont(ofSize: 17)

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:

swift
1import UIKit
2
3func boldItalicFont(size: CGFloat) -> UIFont {
4    let descriptor = UIFont.systemFont(ofSize: size)
5        .fontDescriptor
6        .withSymbolicTraits([.traitBold, .traitItalic])!
7    return UIFont(descriptor: descriptor, size: size)
8}
9
10label.font = boldItalicFont(size: 17)

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:

swift
1import UIKit
2
3let text = NSMutableAttributedString(string: "Total: 42 items")
4text.addAttribute(.font,
5                  value: UIFont.boldSystemFont(ofSize: 17),
6                  range: NSRange(location: 0, length: 5))
7text.addAttribute(.font,
8                  value: UIFont.italicSystemFont(ofSize: 17),
9                  range: NSRange(location: 6, length: 2))
10
11label.attributedText = 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:

swift
label.font = UIFont(name: "AvenirNext-BoldItalic", size: 17)

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 font when the entire label shares one style
  • use attributedText when 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 UILabel to combine bold and italic automatically without a suitable font face.
  • Hard-coding a custom font name that does not actually exist.
  • Using font when only part of the label should be styled.
  • Replacing attributedText later with text and losing formatting.
  • Assuming every font family supports the same trait combinations.

Summary

  • Use UIFont.boldSystemFont or UIFont.italicSystemFont when the whole label uses one style.
  • Use a font descriptor when you want bold and italic traits together.
  • Use NSAttributedString when 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
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.