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.
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.
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.
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.
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.
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.
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
UIBarButtonItemwith 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
- Removing viewcontrollers from navigation stack
- Renew Provisioning Profile
- Renew Push certificate and keep current App Store App working
- Replace Fragment inside a ViewPager
- Replacement for deprecated -sizeWithFontconstrainedToSizelineBreakMode in iOS 7?
- Replacement for stringByAddingPercentEscapesUsingEncoding in ios9?
- Request failed unacceptable content-type text/html using AFNetworking 2.0
- Request Permission for Camera and Library in iOS 10 - Info.plist
.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.