Skip to content

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
            └─ UITabBarItem

Constructor ​

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 ​

PropertyDescription
titleThe text
imageThe icon
isEnabledWhether it can be tapped
tagA 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 ​

ObjCJS
item.title = @"Submit"item.title = 'Submit'
item.image = imgitem.image = img
item.enabled = NOitem.isEnabled = false
item.tag = 7item.tag = 7

See also ​