UITabBar Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 2.0 and later.
Companion guide
Declared in
UITabBar.h
Related sample code

Overview

The UITabBar class implements a control for selecting one of two or more buttons, called items. The most common use of a tab bar is to implement a modal interface where tapping an item changes the selection. Use a UIToolbar object if you want to momentarily highlight or not change the appearance of an item when tapped. The UITabBar class provides the ability for the user to customize the tab bar by reordering, removing, and adding items to the bar. You can use a tab bar delegate to augment this behavior.

Use the UITabBarItem class to create items and the setItems:animated: method to add them to a tab bar. All methods with an animated: argument allow you to optionally animate changes to the display. Use the selectedItem property to access the current item.

Customizing Appearance

In iOS v5.0 and later, you can customize the appearance of tab bars using the methods listed in “Customizing Appearance.” You can customize the appearance of all tab bars using the appearance proxy (for example, [UITabBar appearance]), or just of a single tab bar.

Tasks

Getting and Setting Properties

Configuring Items

Customizing Tab Bars

Customizing Appearance

Properties

backgroundImage

The background image for the bar.

@property(nonatomic, retain) UIImage *backgroundImage
Discussion

A stretchable background image is stretched, a non-stretchable background image is tiled.

Availability
  • Available in iOS 5.0 and later.
Declared In
UITabBar.h

delegate

The tab bar’s delegate object.

@property(nonatomic, assign) id<UITabBarDelegate> delegate
Discussion

The delegate should conform to the UITabBarDelegate protocol. Set this property to further modify the customizing behavior. The default value is nil.

Availability
  • Available in iOS 2.0 and later.
Declared In
UITabBar.h

items

The items displayed on the tab bar.

@property(nonatomic, copy) NSArray *items
Discussion

The items, instances of UITabBarItem, that are visible on the tab bar in the order they appear in this array. Any changes to this property are not animated. Use the setItems:animated: method to animate changes.

The default value is nil.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UITabBar.h

selectedImageTintColor

The tint color to apply to the gradient image used when creating the selected image.

@property(nonatomic, retain) UIColor *selectedImageTintColor
Discussion

The default value is nil, which results in the system bright blue being used for selected tab item images.

If you want to also customize the unselected image appearance, you must sent setFinishedSelectedImage:withFinishedUnselectedImage: to individual tab bar items.

Availability
  • Available in iOS 5.0 and later.
Declared In
UITabBar.h

selectedItem

The currently selected item on the tab bar.

@property(nonatomic, assign) UITabBarItem *selectedItem
Discussion

Changes to this property show visual feedback in the user interface. The selected and unselected images displayed by an item are automatically created based on the alpha values in its original image property that you set. The default value is nil.

Availability
  • Available in iOS 2.0 and later.
Related Sample Code
Declared In
UITabBar.h

selectionIndicatorImage

The image used for the selection indicator.

@property(nonatomic, retain) UIImage *selectionIndicatorImage
Discussion

The selection indicator image is drawn on top of the tab bar, behind the bar item icon.

Availability
  • Available in iOS 5.0 and later.
Declared In
UITabBar.h

shadowImage

The shadow image to be used for the tab bar.

@property(nonatomic,retain) UIImage *shadowImage
Discussion

The default value is nil, which corresponds to the default shadow image. When non-nil, this property represents a custom shadow image to show instead of the default. For a custom shadow image to be shown, a custom background image must also be set using the backgroundImage property. If the default background image is used, then the default shadow image will be used regardless of the value of this property.

Availability
  • Available in iOS 6.0 and later.
Declared In
UITabBar.h

tintColor

The tint color to apply to the tab bar background.

@property(nonatomic, retain) UIColor *tintColor
Availability
  • Available in iOS 5.0 and later.
Declared In
UITabBar.h

Instance Methods

beginCustomizingItems:

Presents a modal view allowing the user to customize the tab bar by adding, removing, and rearranging items on the tab bar.

- (void)beginCustomizingItems:(NSArray *)items
Parameters
items

The items to display on the modal view that can be rearranged.

The items parameter should contain all items that can be added to the tab bar. Visible items not in items are fixed in place—they can not be removed or replaced by the user.

Discussion

Use this method to start customizing a tab bar. For example, create an Edit button that invokes this method when tapped. A modal view appears displaying all the items in items with a Done button at the top. Tapping the Done button dismisses the modal view. If the selected item is removed from the tab bar, the selectedItem property is set to nil. Set the delegate property to an object conforming to the UITabBarDelegate protocol to further modify this behavior.

Availability
  • Available in iOS 2.0 and later.
Declared In
UITabBar.h

endCustomizingAnimated:

Dismisses the modal view used to modify items on the tab bar.

- (BOOL)endCustomizingAnimated:(BOOL)animated
Parameters
animated

If YES, animates the transition; otherwise, does not.

Return Value

YES if items on the tab bar changed; otherwise, NO.

Discussion

Typically, you do not need to use this method because the user dismisses the modal view by tapping the Done button.

Availability
  • Available in iOS 2.0 and later.
Declared In
UITabBar.h

isCustomizing

Returns a Boolean value indicating whether the user is customizing the tab bar.

- (BOOL)isCustomizing
Return Value

YES if the user is currently customizing the items on the tab bar; otherwise, NO. For example, by tapping an Edit button, a modal view appears allowing users to change the items on a tab bar. This method returns YES if this modal view is visible.

Availability
  • Available in iOS 2.0 and later.
Declared In
UITabBar.h

setItems:animated:

Sets the items on the tab bar, with or without animation.

- (void)setItems:(NSArray *)items animated:(BOOL)animated
Parameters
items

The items to display on the tab bar.

animated

If YES, animates the transition to the items; otherwise, does not.

Discussion

If animated is YES, the changes are dissolved or the reordering is animated—for example, removed items fade out and new items fade in. This method also adjusts the spacing between items.

Availability
  • Available in iOS 2.0 and later.
Declared In
UITabBar.h

Did this document help you? Yes It's good, but... Not helpful...