IOS UINavigationBar-navigation bar, UINavigationItem-Navigation item, iosuinavigationitem

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.