UILabel
iOS Development
Swift
Text Styling
UIKit

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 a UILabel bold or italic, you set its font to a UIFont that carries the desired traits. If the entire label uses one style, a font change is enough. If only part of the text should be bold or italic, use an attributed string instead of a plain string.

Set a Uniform Bold Font

For a label where the whole text should be bold, the simplest solution is a system bold font:

swift
1import UIKit
2
3let label = UILabel()
4label.text = "Important"
5label.font = UIFont.boldSystemFont(ofSize: 18)

This is the most direct solution when you only need bold styling and do not care about mixing traits in the same label.

Set an Italic Font with a Descriptor

UIKit has a convenience method for bold system fonts, but italic styling is commonly done through a font descriptor.

swift
1import UIKit
2
3let label = UILabel()
4label.text = "Emphasis"
5
6let baseFont = UIFont.systemFont(ofSize: 18)
7if let descriptor = baseFont.fontDescriptor.withSymbolicTraits(.traitItalic) {
8    label.font = UIFont(descriptor: descriptor, size: 18)
9}

This asks the system font for an italic variant. If the descriptor cannot produce the requested trait, the fallback should remain a readable non-italic font rather than crashing.

Combine Bold and Italic

If you want the label font to be both bold and italic, combine the symbolic traits:

swift
1import UIKit
2
3let label = UILabel()
4label.text = "Strong emphasis"
5
6let baseFont = UIFont.systemFont(ofSize: 18)
7if let descriptor = baseFont.fontDescriptor.withSymbolicTraits([.traitBold, .traitItalic]) {
8    label.font = UIFont(descriptor: descriptor, size: 18)
9}

Whether this produces the exact look you want depends on the font family. Some fonts support the combined face directly, and others approximate it less elegantly.

Use NSAttributedString for Partial Styling

If only one word or range should be bold or italic, assign an attributed string to attributedText.

swift
1import UIKit
2
3let label = UILabel()
4let text = "Normal Bold Italic"
5let attributed = NSMutableAttributedString(string: text)
6
7attributed.addAttribute(
8    .font,
9    value: UIFont.systemFont(ofSize: 18),
10    range: NSRange(location: 0, length: text.count)
11)
12
13attributed.addAttribute(
14    .font,
15    value: UIFont.boldSystemFont(ofSize: 18),
16    range: NSRange(location: 7, length: 4)
17)
18
19if let italicDescriptor = UIFont.systemFont(ofSize: 18)
20    .fontDescriptor
21    .withSymbolicTraits(.traitItalic) {
22    attributed.addAttribute(
23        .font,
24        value: UIFont(descriptor: italicDescriptor, size: 18),
25        range: NSRange(location: 12, length: 6)
26    )
27}
28
29label.attributedText = attributed

This is the right approach when different parts of the label need different emphasis.

Custom Fonts Need Actual Available Faces

If you use a custom font family, do not assume that adding symbolic traits to one font face will always produce a valid bold or italic version. Many custom fonts ship separate face names such as:

  • 'MyFont-Regular'
  • 'MyFont-Bold'
  • 'MyFont-Italic'
  • 'MyFont-BoldItalic'

In those cases, loading the exact face by name is more reliable than asking the descriptor system to synthesize traits.

Consider Dynamic Type

If the label participates in Dynamic Type, keep accessibility in mind. Styling and sizing are separate concerns. You can use UIFontMetrics to scale a styled font so bold or italic text still responds correctly to the user's text size settings.

Common Pitfalls

  • Using text when the requirement really needs attributedText.
  • Assuming every font supports italic or bold-italic variants.
  • Replacing the whole font and accidentally losing Dynamic Type behavior.
  • Applying one font to the entire label when only part of the text should be emphasized.
  • Expecting symbolic traits to work identically across all custom font families.

Summary

  • Use UIFont.boldSystemFont when the whole label should be bold.
  • Use a font descriptor with .traitItalic for italic styling.
  • Combine traits for bold-italic when the font supports it.
  • Use NSAttributedString for mixed styles within one label.
  • With custom fonts, prefer loading real face names instead of assuming traits can be synthesized.

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.