iOS development-ui (vi) Navigation

Source: Internet
Author: User

Knowledge Points:

1.UINavigationController

2.UINavigationItem

3.UINavigationBar

4.UINavigationController View Toggle

========================

Uinavigationcontroller

1. What is a navigation controller

Role: Managing the View Controller

2.UINavigationController Object creation

1) Initialization mode

-(ID) Initwithrootviewcontroller: (Uiviewcontroller *) Rootviewcontroller

2) Uinavigationcontroller Composition:

(1) Navigationbar (height 44)

(2) customcontent-has a custom viewcontroller provided

(3) Navigationtoolbar (height 44)

3. Switching views by Uinavigationcontroller objects

1) Press the view controller into the stack container of the navigation controller

-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller

Animated: (BOOL) animated

2) Eject the view controller from the navigation controller

-(Uiviewcontroller *) popviewcontrolleranimated: (BOOL) animated

========================

Uinavigationitem

The Uinavigationitem contains:

(1) Backbarbuttonitem (determined by the properties of the above-level CTL)

(2) Title/titleview (current CTL)

(3) Rightbarbuttonitem (current CTL)

(4) Leftbarbuttonitem (current CTL)

1.UINavigationItem and Uiviewcontroller relationships

Navigationitem is a property of Uiviewcontroller

This property is for Uinavigationcontroller service.

2. Create Uibarbuttonitem

1) Create the Uibarbuttonsystemitem that comes with the system

-(ID) Initwithbarbuttonsystemitem: (uibarbuttonsystemitem) Systemitem

target: (ID) Target

Action: (SEL) Action;

Self.navigationItem.leftBarButtonItem = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem: Uibarbuttonsystemitembookmarks target:self Action: @selector (btnaction)];

2) How to create text Uibarbuttonitem

-(ID) Initwithtitle: (NSString *) title

style: (uibarbuttonitemstyle) style

target: (ID) Target

action: (SEL) Action

Self.navigationItem.rightBarButtonItem = [[Uibarbuttonitem new];

3) How to create a picture Uibarbuttonitem

-(ID) initwithimage: (UIImage *) image

style: (uibarbuttonitemstyle) style

target: (ID) Target

action: (SEL) Action

Self.navigationItem.backBarButtonItem = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@ "refresh_30"] Style:uibarbuttonitemstyleplain Target:nil Action:nil];

3) How to add Uibarbuttonitem to the left and right of the navigation

@property (nonatomic, retain) Uibarbuttonitem *leftbarbuttonitem

@property (nonatomic, retain) Uibarbuttonitem *rightbarbuttonitem

@property (nonatomic, retain) Uibarbuttonitem *backbarbuttonitem

Self.navigationItem.rightBarButtonItem = [[Uibarbuttonitem alloc] initwithcustomview:b];

3. Custom Uibarbuttonitem

4. Customizing the Titleview in the middle of navigation

Self.navigationItem.title = @ "Controller 2";

5. Custom Backbarbuttonitem

Note: Setting the Backbarbuttonitem of the current controller needs to be displayed in the next control

========================

Uinavigationbar

1. How to map Uinavigationbar

set a background picture

-(void) SetBackgroundImage: (UIImage *) backgroundimage

Forbarmetrics: (uibarmetrics) Barmetrics

[Self.navigationController.navigationBar setbackgroundimage:[uiimage imagenamed:@ "1.png"] forbarmetrics: Uibarmetricsdefault];

2. How to set the Uinavigationbar setting color

@property (nonatomic, retain) Uicolor *tintcolor

@property (nonatomic, retain) Uicolor *bartintcolor

3. How to set the transparent color

1) Set the style of the Uinavigationbar

@property (nonatomic, assign) Uibarstyle Barstyle

self.navigationcontroller.navigationbar.barstyle= Uibarstyleblack;

2) is transparent

@property (nonatomic, assign, getter=istranslucent) BOOL Translucent

Gets the navigation controller that manages the current view controller (this method returns a null pointer if the view controller is not managed by the navigation controller)

Set the navigation bar to opaque, the coordinate point will automatically move down by 64 units

Self.navigationController.navigationBar.translucent = NO;

3) Change the color of the navigation bar

@property (nonatomic,retain) Uicolor *bartintcolor

Set Background color

Self.navigationController.navigationBar.barTintColor = [Uicolor colorwithred:arc4random ()%256/255.0 Green: Arc4random ()%256/255.0 blue:arc4random ()%256/255.0 alpha:1.0];

4. How to hide Uinavigationbar

1) Hide without animation

@property (nonatomic, Getter=isnavigationbarhidden) BOOL Navigationbarhidden

Show

Self.navigationController.navigationBarHidden = NO;

2) drive the painting to hide

-(void) Setnavigationbarhidden: (BOOL) Navigationbarhidden

Animated: (BOOL) animated

[Self.navigationcontroller Setnavigationbarhidden:yes Animated:yes];

========================

Uinavigationcontroller View Toggle

1. Get an array of views in the navigation controller

@property (nonatomic, copy) Nsarray *viewcontrollers

2. Press the view controller into the stack container of the navigation controller

-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller

Animated: (BOOL) animated

View Controller in Stack

[Self.navigationcontroller Pushviewcontroller:ctla Animated:yes];

3. Eject the view controller from the navigation controller

-(Uiviewcontroller *) popviewcontrolleranimated: (BOOL) animated

4. Switch to the specified view controller (the controller must be in the stack in the current navigation controller)

-(Nsarray *) Poptoviewcontroller: (Uiviewcontroller *) Viewcontroller

Animated: (BOOL) animated

5. Back to the root view controller

-(Nsarray *) poptorootviewcontrolleranimated: (BOOL) Animated

iOS development-ui (vi) Navigation

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.