iOS development
UIBarButtonItem
Swift programming
iOS UI customization
iOS interface design

Removing the title text of an iOS UIBarButtonItem

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Removing the title text from a UIBarButtonItem is usually straightforward, but the best method depends on what kind of bar button you actually want. If you only want an icon, create the item with an image and no title. If you already have a titled item, set its title to an empty string or use a custom view. The real job is to remove the visible text without hurting layout or accessibility.

Create an Image-Only Bar Button Item

If the button should be icon-only, the cleanest solution is to build it that way from the start.

swift
1let settingsButton = UIBarButtonItem(
2    image: UIImage(systemName: "gearshape"),
3    style: .plain,
4    target: self,
5    action: #selector(openSettings)
6)
7
8navigationItem.rightBarButtonItem = settingsButton

This avoids title text entirely and usually produces the clearest result.

Remove the Title from an Existing Button

If you already have a text-based item, setting the title to an empty string removes the visible text.

swift
let button = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(doneTapped))
button.title = ""
navigationItem.rightBarButtonItem = button

This works, but it is usually best when the button also has an image or when the surrounding context makes the button's purpose obvious.

Use a Custom View for Full Control

If the built-in bar button item API is too limiting, provide a custom view.

swift
1let iconButton = UIButton(type: .system)
2iconButton.setImage(UIImage(systemName: "trash"), for: .normal)
3iconButton.addTarget(self, action: #selector(deleteTapped), for: .touchUpInside)
4
5let barItem = UIBarButtonItem(customView: iconButton)
6navigationItem.rightBarButtonItem = barItem

A custom view gives you control over spacing, image configuration, and tap behavior, but it also makes you more responsible for sizing and accessibility.

Hiding Back Button Text Is a Special Case

If the text you want to remove is the back button title, that is a slightly different problem. You usually configure the back button display from the previous view controller.

swift
1override func viewDidLoad() {
2    super.viewDidLoad()
3    navigationItem.backButtonDisplayMode = .minimal
4}

This is often a better answer than manually forcing an empty back button title.

Do Not Forget Accessibility

If you remove visible text, VoiceOver still needs a meaningful description.

swift
settingsButton.accessibilityLabel = "Settings"
settingsButton.accessibilityHint = "Opens the settings screen"

A purely visual icon is not enough for all users. Removing title text should not remove meaning.

In navigation bars, this also affects spacing and visual balance. Removing text may make the bar look cleaner, but it can also make tap targets feel ambiguous if the iconography is weak or inconsistent with the rest of the app.

That tradeoff is most visible in crowded toolbars and navigation bars, where one missing word can save space but also remove the last obvious clue about what the control actually does.

Common Pitfalls

The biggest mistake is removing text without providing a clear image or enough context. A blank-looking navigation item can make the UI harder to understand.

Another issue is confusing normal bar button items with back button text. Back button title behavior has separate APIs and should be handled differently.

People also often use a custom view too early. A standard image-based UIBarButtonItem is simpler and integrates better with the navigation bar unless you truly need custom sizing or behavior.

Finally, if you remove the title from a text-only button and do not add accessibility metadata, the result may look cleaner visually while becoming less usable overall.

Summary

  • For icon-only buttons, create the UIBarButtonItem with an image and no title.
  • You can remove visible text from an existing item by setting its title to an empty string.
  • Use a custom view only when the standard item API is not enough.
  • Treat back button text removal as a separate navigation-bar case.
  • Preserve usability with clear icons and proper accessibility labels.

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.