IOS UINavigationBar-navigation bar, UINavigationItem-Navigation item, iosuinavigationitem
1. What is the navigation bar (UINavigationBar ).
UINavigationBar is an attribute of UINavigationController. Is an integral part of the navigation bar controller.
* A navigation bar controller contains a navigation bar (UINavigationBar)
* A sub-controller corresponds to a navigation item (UINavigationItem)
* The navigation controller manages a series of subcontrollers. UINavigationBar manages a series of uinavigationitems. Each UINavigationItem corresponds to a subcontroller.
Note:The light blue part is the UINavigationItem, And the NavigationItem is on The View Controller. It is an attribute of the controller and is also an integral part, not on the NavigationBar, so you will see self in viewController. navigationItem code. Every time UINvigationController pushes a UINavigationBar, it corresponds to the corresponding UINavigationItem.
2. Set the title of the navigation bar (UINavigationBar ).
1. Use the built-in title in the navigation bar
In the attempt to Controller viewController, use self. title = @ "navigation bar title"; then OK.
2. Custom navigation bar title
UINavigationItem has several common attributes: (extracted from the document, partial attributes)
@ Property (nonatomic, copy) NSString * title; // title
@ Property (nonatomic, retain) UIView * titleView; // This is a view. Everything that can be placed on the view can be placed on it. You can customize the title based on this attribute, or add an image background.
@ Property (nonatomic, copy) NSArray * leftBarButtonItems NS_AVAILABLE_IOS (5_0); // you can put a button on the navigation bar (UINavigationItem. The button on the left, of course, also has the button on the right. The principle is the same as below.
@ Property (nonatomic, copy) NSArray * rightBarButtonItems NS_AVAILABLE_IOS (5_0 );
@ Property (nonatomic, retain) UIBarButtonItem * leftBarButtonItem;
@ Property (nonatomic, retain) UIBarButtonItem * rightBarButtonItem;
Customize the title of the navigation bar based on the titleView attribute:
UILabel * titleLabel = [[UILabel alloc] initWithFrame: CGRectMake (0, 0,100, 44)];
TitleLabel. backgroundColor = [UIColor redColor];
TitleLabel. text = @ "My View Controller ";
Self. navigationItem. titleView = titleLabel;
After writing this, we will find the title of viewController.