Skip to content

UITabBarItem ​

UITabBarItem represents one tab in the bottom tab bar: the icon, the text below the icon, and the badge in the top-right corner. It hangs on a view controller's tabBarItem and is shown once the view controller is put into a UITabBarController.

The title, icon, whether it can be tapped, and the tag number are inherited from UIBarItem.

Inheritance: EventTarget → NSObject → UIBarItem → UITabBarItem

Constructor ​

UITabBarItem()

Creates a tab, optionally with a title, icon, selected icon, tag number, and badge at the same time.

Instance properties ​

Also inherits the properties of UIBarItem: title (the text below the icon), image (the icon), isEnabled (when false, grayed out and not tappable; how it looks is not verified in the simulator), and tag.

PropertyDescription
selectedImageThe icon used when selected
badgeValueThe text in the badge in the top-right corner
badgeColorThe badge's background color

None of these properties fires an event when it changes: only code changes them.

Examples ​

js
const home = new UIViewController();
home.tabBarItem = new UITabBarItem({
  title: 'Home',
  image: UIImage.systemImageNamed('house'),
  selectedImage: UIImage.systemImageNamed('house.fill'),
});
home.tabBarItem.badgeValue = '3';
console.log(home.tabBarItem.title, home.tabBarItem.badgeValue);

Result: The console prints Home 3. After the view controller is put into a tab bar controller, its tab shows a house icon and "Home", with a red badge of 3 in the top-right corner. How it looks is not verified in the simulator.

Corresponding iOS API ​

ObjCJS
[[UITabBarItem alloc] initWithTitle:@"Home" image:img selectedImage:sel]new UITabBarItem({ title: 'Home', image: img, selectedImage: sel })
item.badgeValue = @"3"item.badgeValue = '3'
item.badgeColor = UIColor.systemIndigoColoritem.badgeColor = 'systemIndigo'

See also ​