UIBarItem
UIBarItem represents the shared part of an item on a navigation bar or tab bar: text, icon, whether it can be tapped, and a tag number. It is the common superclass of UIBarButtonItem (a button on the navigation bar) and UITabBarItem (a tab on the tab bar), and cannot be created itself.
Inheritance: EventTarget → NSObject → UIBarItem
EventTarget
└─ NSObject
└─ UIBarItem
├─ UIBarButtonItem
└─ UITabBarItemConstructor
Cannot be created with new. new UIBarItem() throws TypeError: Illegal constructor: UIBarItem is abstract; construct UIBarButtonItem instead. Create its subclass UIBarButtonItem; a UITabBarItem comes with each view controller.
Instance properties
| Property | Description |
|---|---|
title | The text |
image | The icon |
isEnabled | Whether it can be tapped |
tag | A number for your own use; the system ignores it |
None of these four properties fires an event when it changes: only code changes them.
Examples
js
const item = new UIBarButtonItem({ title: 'Submit' });
item.isEnabled = false;
item.tag = 7;
console.log(item instanceof UIBarItem, item.title, item.isEnabled, item.tag);Result: The console prints true Submit false 7.
Corresponding iOS API
| ObjC | JS |
|---|---|
item.title = @"Submit" | item.title = 'Submit' |
item.image = img | item.image = img |
item.enabled = NO | item.isEnabled = false |
item.tag = 7 | item.tag = 7 |
See also
UIBarButtonItem: buttons on the navigation barUITabBarItem: tabs on the tab bar