| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iPhone OS 2.0 and later. |
| Declared in | UINavigationBar.h |
| Related sample code |
The UINavigationItem class encapsulates information about a navigation item pushed on a UINavigationBar object’s stack. A navigation bar is a control used to navigate hierarchical content. A UINavigationItem specifies what is displayed on the navigation bar when it is the top item and also how it is represented when it is the back item.
Use the initWithTitle: method to create a navigation item specifying the item’s title. The item cannot be represented on the navigation bar without a title. Use the backBarButtonItem property if you want to use a different title when this item is the back item. The backBarButtonItem property is displayed as the back button unless a custom left view is specified.
The navigation bar displays a back button on the left and the title in the center by default. You can change this behavior by specifying either a custom left, center, or right view. Use the setLeftBarButtonItem:animated: and setRightBarButtonItem:animated: methods to change the left and right views; you can specify that the change be animated. Use the titleView method to change the center view to a custom view.
These custom views can be system buttons. Use the UIBarButtonItem class to create custom views to add to navigation items.
title property
prompt property
backBarButtonItem property
hidesBackButton property
– setHidesBackButton:animated:
titleView property
leftBarButtonItem property
rightBarButtonItem property
– setLeftBarButtonItem:animated:
– setRightBarButtonItem:animated:
For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.
The bar button item to use when this item is represented by a back button on the navigation bar.
@property(nonatomic, retain) UIBarButtonItem *backBarButtonItem
When this item is the back item of the navigation bar—when it is the next item below the top item—it may be represented as a back button on the navigation bar. Use this property to specify the back button. The target and action of the back bar button item you set should be nil. The default value is a bar button item displaying the navigation item’s title.
UINavigationBar.hA Boolean value that determines whether the back button is hidden.
@property(nonatomic, assign) BOOL hidesBackButton
YES if the back button is hidden when this navigation item is the top item; otherwise, NO. The default value is NO.
UINavigationBar.hA custom bar item displayed on the left of the navigation bar when this item is the top item.
@property(nonatomic, retain) UIBarButtonItem *leftBarButtonItem
UINavigationBar.hA single line of text displayed at the top of the navigation bar.
@property(nonatomic, copy) NSString *prompt
The default value is nil.
UINavigationBar.hA custom bar item displayed on the right of the navigation bar when this item is the top item.
@property(nonatomic, retain) UIBarButtonItem *rightBarButtonItem
UINavigationBar.hThe navigation item’s title displayed in the center of the navigation bar.
@property(nonatomic, copy) NSString *title
The default value is nil.
UINavigationBar.hA custom view displayed in the center of the navigation bar when this item is the top item.
@property(nonatomic, retain) UIView *titleView
If this property value is nil, the navigation item’s title is displayed in the center of the navigation bar when this item is the top item. If you set this property to a custom title, it is displayed instead of the title. This property is ignored if leftBarButtonItem is not nil.
Custom views can contain buttons. Use the buttonWithType: method in UIButton class to add buttons to your custom view in the style of the navigation bar. Custom title views are centered on the navigation bar and may be resized to fit.
The default value is nil.
UINavigationBar.hReturns a navigation item initialized with the specified title.
- (id)initWithTitle:(NSString *)title
The string to set as the navigation item’s title displayed in the center of the navigation bar.
A new UINavigationItem object initialized with the specified title.
This is the designated initializer for this class.
UINavigationBar.hSets whether the back button is hidden, optionally animating the transition.
- (void)setHidesBackButton:(BOOL)hidesBackButton animated:(BOOL)animated
YES if the back button is hidden when this navigation item is the top item; otherwise, NO.
YES to animate the transition; otherwise, NO.
UINavigationBar.hSets the custom bar item, optionally animating the transition to the view.
- (void)setLeftBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated
A custom bar item to display on the left of the navigation bar.
YES to animate the transition to the custom bar item when this item becomes the top item; otherwise, NO.
If two navigation items have the same custom left or right bar items, the views remain stationary during the transition when an item is pushed or popped.
UINavigationBar.hSets the custom bar item, optionally animating the transition to the view.
- (void)setRightBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated
A custom bar item to display on the right of the navigation bar.
YES to animate the transition to the custom bar item when this item becomes the top item; otherwise, NO.
If two navigation items have the same custom left or right bar items, the bar items remain stationary during the transition when an item is pushed or popped.
UINavigationBar.hLast updated: 2008-06-09