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 |
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
-
delegateproperty
Configuring Items
-
itemsproperty -
selectedItemproperty -
– setItems:animated:
Customizing Tab Bars
Customizing Appearance
-
backgroundImageproperty -
selectedImageTintColorproperty -
selectionIndicatorImageproperty -
shadowImageproperty -
tintColorproperty
Properties
backgroundImage
The background image for the bar.
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.hdelegate
The tab bar’s delegate object.
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.hitems
The items displayed on the tab bar.
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.
Declared In
UITabBar.hselectedImageTintColor
The tint color to apply to the gradient image used when creating the selected image.
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.hselectedItem
The currently selected item on the tab bar.
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.
See Also
Declared In
UITabBar.hselectionIndicatorImage
The image used for the selection indicator.
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.hshadowImage
The shadow image to be used for the tab bar.
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.htintColor
The tint color to apply to the tab bar background.
Availability
- Available in iOS 5.0 and later.
Declared In
UITabBar.hInstance Methods
beginCustomizingItems:
Presents a modal view allowing the user to customize the tab bar by adding, removing, and rearranging items on the tab bar.
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.
See Also
Declared In
UITabBar.hendCustomizingAnimated:
Dismisses the modal view used to modify items on the tab bar.
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.
See Also
Declared In
UITabBar.hisCustomizing
Returns a Boolean value indicating whether the user is customizing the tab bar.
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.hsetItems:animated:
Sets the items on the tab bar, with or without animation.
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.
See Also
Declared In
UITabBar.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)