Common functions of iOS navigation controllers and common attributes of navigationBar

Source: Internet
Author: User

Common functions of iOS navigation controllers and common attributes of navigationBar
Common Function triggering time of navigation Controller

Triggered when the View of the View Controller is about to appear

-(Void) viewWillAppear :( BOOL) animated

Triggered when View of the View Controller already appears

-(Void) viewDidAppear :( BOOL) animated

Triggered when the View of the View Controller is about to disappear

-(Void) viewWillDisappear :( BOOL) animated

Triggered when View of the View Controller disappears

-(Void) viewDidDisappear :( BOOL) animated


When the previous interface pushes the next interface, such as A push B, the four methods are executed in sequence A (ViewWillDisappear)> B (viewWillAppear)> A (viewDidDisappear)> B (viewDidAppear)

When the last interface pops the previous interface, such as B pop A, four methods are executed in sequence B (viewWillDisappear)> A (viewWillAppear)> B (viewDidDisappear)> A (viewDidAppear)

Common navigationBar attributes
1. Directly configure the navigationBar. Therefore, this operation will affect the content displayed on the navigationBar of each interface (the effect is the same)
1. Modify the navigationBar color

Self. navigationController. navigationBar. barTintColor = [UIColor redColor];

2. Disable the glass effect of navigationBar

Self. navigationController. navigationBar. translucent = NO;

3. Hide navigationBar

Self. navigationController. navigationBarHidden = YES;

4. Set an image for navigationBar

Images of different sizes have different effects:
1.320*44, will only attach a piece to the navigationBar

2. The height is less than 44 and greater than 44 and less than 64: The navigationBar is tiled and the status bar is displayed.

3. height equal to 64: the entire image is displayed on the navigationBar and status bar.


[Self. navigationController. navigationBar setBackgroundImage: [UIImage imageNamed: @ "32050"] forBarMetrics: UIBarMetricsDefault];

2. Customize the content displayed on the navigationBar of each interface separately (the content displayed on each interface is different)
Modify the navigationItem of the View Controller.

1. Set the title of the interface
Self. navigationItem. title = @ "Far East development ";
2. Modify titleView (intermediate display view)
UISegmentedControl * segment = [[UISegmentedControlalloc] initWithItems: @ [@ "group", @ "friend"]; self. navigationItem. titleView = segment; [segment release];
3. Modify the color of navigationBar self. navigationController. navigationBar. barTintColor = [UIColor whiteColor];

4. Modify the navigationBar. The content is displayed on the right.
UIBarButtonItem * right = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd target: self action: @ selector (add :)];

Self. navigationItem. rightBarButtonItem = right;

[Right release];
5. Modify the navigationBar. The content is displayed on the left.
UIBarButtonItem * left = [[UIBarButtonItemalloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAddtarget: selfaction: @ selector (add :)];

Self. navigationItem. leftBarButtonItem = left;

[Left release];



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.