Ui-uinavigationcontroller Uitabbarcontroller Use Summary

Source: Internet
Author: User

#pragma mark-uinavigationcontroller Uitabbarcontroller ======================================

Controller switching mode--Push/model uinavigationcontroller 5th and Uitabbarcontroller 4th have instructions for use

First, Uinavigationcontroller

1. An iOS app rarely consists of a single controller, unless the app is extremely simple, we need to manage these controllers when there are multiple controllers in the app, and the navigation controller is just a container that can push or eject multiple view controllers in the navigation controller. The navigation controller manages these view controllers in the form of a stack structure

2. To facilitate the management of the Controller, iOS offers 2 more special controllers--Uinavigationcontroller/uitabbarcontroller

3. Uinavigationcontroller has Navigation bar, Navigation View, Navigation Toobar and other components.

4. Steps to use Uinavigationcontroller

4.1 Initializing Uinavigationcontroller

4.2 Setting UIWindow Rootviewcontroller to Uinavigationcontroller

4.3 Add the corresponding number of sub-controllers by the push method, depending on the situation

5. Uinavigationcontroller's sub-controller

5.1 Uinavigationcontroller Save the sub-controller as a stack

@property (nonatomic,copy) Nsarray *viewcontrollers;

@property (nonatomic,readonly) Nsarray *childviewcontrollers;

5.2 A controller can be pressed into the stack using the Push method

-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;

5.3 Use the Pop method to remove the controller

5.31 Remove the controller from the top of the stack

-(Uiviewcontroller *) popviewcontrolleranimated: (BOOL) animated;

5.32 back to the specified sub-controller

-(Nsarray *) Poptoviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;

5.33 Back to root controller (stack bottom controller)

-(Nsarray *) poptorootviewcontrolleranimated: (BOOL) animated;

5.4 About pushviewcontroller:animated: The animation effect generally we use the default animation on the line, but we can also customize the animation content, we can use catransition to achieve the conversion animation effect, the code is as follows:

-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{

if (Indexpath.row = = 0) {

Oneviewcontroller *oneviewcontroller = [[Oneviewcontroller alloc] init];

Catransition *animation = [catransition animation];

[Animation setduration:0.5];

[Animation Settype:kcatransitionmovein];

[Animation Setsubtype:kcatransitionfromtop];

[Animation settimingfunction:[camediatimingfunction Functionwithname:kcamediatimingfunctiondefault];

[Self.navigationcontroller Pushviewcontroller:oneviewcontroller Animated:no];

Oneviewcontroller = nil;

[Self.navigationController.view.layer addanimation:animation Forkey:nil];

}

}

6. Modify the contents of the navigation bar

The contents of the navigation bar are determined by the Navigationitem property of the stack top controller

Uinavigationitem has the following properties that affect the contents of the navigation bar

6.1 Back button in upper left corner

@property (Nonatomic,retain) Uibarbuttonitem *backbarbuttonitem;

6.2 Title view in the middle

@property (Nonatomic,retain) UIView *titleview;

6.3 Title text in the middle

@property (nonatomic,copy) NSString *title;

6.4 View in the upper-left corner

@property (Nonatomic,retain) Uibarbuttonitem *leftbarbuttonitem;

6.5 Uibarbuttonitem *rightbarbuttonitem The upper right corner of the view

@property (Nonatomic,retain) Uibarbuttonitem *rightbarbuttonitem;

7. Set whether the navigation bar is displayed

Setnavigationbarhidden:bool Animated:bool

8. Toolbar is hidden by default in Uinavigationcontroller, which can be displayed by the following code.

Self.navigationController.toolbarHidden = NO; Or

[Self.navigationcontroller Settoolbarhidden:no Animated:yes];

9. Set some properties of the navigation bar

9.1 Defining a navigation controller, initializing the root view of the navigation controller

Viewcontroller *ROOTVC = [[Viewcontroller alloc]init];

Uinavigationcontroller *NAVVC = [[Uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:ROOTVC];

9.2 style of the navigation bar

NavVC.navigationBar.barStyle = Uibarstyledefault;

9.3 The navigation bar is transparent by default, the origin of the coordinates is in the upper left corner of the screen, and if the navigation bar is set to opaque, the coordinates origin is in the upper-left corner below the navigation bar.

NavVC.navigationBar.translucent = YES;

NavVC.navigationBar.backgroundColor = [Uicolor Yellowcolor];

9.4 Set the color of the button text on the left and right sides of the navigation bar

NavVC.navigationBar.tintColor = [Uicolor Orangecolor];

9.5 Setting the color of the navigation bar

NavVC.navigationBar.barTintColor = [Uicolor Greencolor];

9.6 When setting the background picture of the navigation bar, it should be noted that the height of the picture should include the height of the status bar 20, if not included, the status bar is black

Requires the background image height of the navigation bar to be 64

[Navvc.navigationbar setbackgroundimage:[uiimage imagenamed:@ "Head"] forbarmetrics:uibarmetricsdefault];

9.7 By default, the title of the navigation controller is the title of the View controller

9.71 is generally a separate set of Navigationitem properties for each sub-controller of the navigation controller

To set the relevant properties for navigation options:

9.72 title

Rootvc.title = @ "XXXX";

By default, the return button is next to the navigation title of the previous view controller setting

9.73 Reset Return button text if the navigation controller's heel controller is the first view controller, you do not need to set a return

Uibarbuttonitem *backitem = [[Uibarbuttonitem alloc]initwithtitle:@ "Back B" Style:uibarbuttonitemstyleplain target:self Action:nil];

RootVC.navigationItem.backBarButtonItem = Backitem;

9.74 Customizing the Right navigation button

Uibarbuttonitem *rightitem = [[Uibarbuttonitem alloc]initwithtitle:@ "NAVVCY" Style:uibarbuttonitemstyleplain target: Self Action:nil];

RootVC.navigationItem.rightBarButtonItem = Rightitem;

9.75 Customizing the Left navigation button

Uibarbuttonitem *leftitem = [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonsystemitemcancel Target: Self Action:nil];

RootVC.navigationItem.leftBarButtonItem = Leftitem;

10. Hide the navigation bar

Self.navigationController.navigationBarHidden = YES;

Second, uitabbarcontroller=======================================================================

1. Simple use of Uitabbarcontroller

Initialize Uitabbarcontroller

Set the Rootviewcontroller for UIWindow to Uitabbarcontroller

Depending on the case, add the corresponding number of sub-controllers by the Addchildviewcontroller method

2. Uitabbarcontroller's sub-controller

There are 2 ways to add a Uitabbarcontroller controller

2.1 Adding a single sub-controller

-(void) Addchildviewcontroller: (Uiviewcontroller *) Childcontroller;

2.2 Setting up a sub-controller array

@property (nonatomic,copy) Nsarray *viewcontrollers;

3. What is displayed inside the Uitabbarbutton, determined by the Tabbaritem property of the corresponding sub-controller

Uitabbaritem has the following properties that affect the content of Uitabbarbutton

3.1 Title text

@property (nonatomic,copy) NSString *title;

3.2 Icons

@property (Nonatomic,retain) UIImage *image;

3.3 Icon When selected

@property (Nonatomic,retain) UIImage *selectedimage;

3.4 Reminder Numbers

@property (nonatomic,copy) NSString *badgevalue;

4. Model

4.1 Display the controller in the form of modal

-(void) Presentviewcontroller: (Uiviewcontroller *) viewcontrollertopresent animated: (BOOL) flag completion: (void (^) ( void)) Completion

4.2 Shut down the original modal controller.

-(void) dismissviewcontrolleranimated: (BOOL) flag completion: (void (^) (void)) completion;

5. Example:

5.1 Create a Controller object first

FIRSTVC *FIRSTVC = [[FIRSTVC alloc]init];

SECONDVC *SECONDVC = [[SECONDVC alloc] init];

THIRDVC *THIRDVC = [[THIRDVC alloc]init];

FOURTHVC *FOURTHVC = [[FOURTHVC alloc]init];

FIFTHVC *FIFTHVC = [[FIFTHVC alloc]init];

SIXTHVC *SIXTHVC = [[SIXTHVC alloc]init];

5.2 Setting the Controller object title

Firstvc.title = @ "First";

Secondvc.title = @ "Second";

Thirdvc.title = @ "Third";

Fourthvc.title = @ "Fourth";

Fifthvc.title = @ "Fifth";

Sixthvc.title = @ "Sixth";

5.3 FIRSTVC with navigation packaging (other controllers can also be packaged)

Uinavigationcontroller *NAVVC = [[Uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:FIRSTVC]

5.4 Creating a Tabbar Controller object

Uitabbarcontroller *TABBARVC = [[Uitabbarcontroller alloc]init];

5.5 Set the Tabbar sub-controller object, note that the Tabbar controller can only display up to five sub-views, if more than 5, it will only display 4, put the other one in the more options

Tabbarvc.viewcontrollers = @[navvc, SECONDVC, THIRDVC, FOURTHVC,FIFTHVC, SIXTHVC];

5.6 Setting the color of the Tabbar bar

TabBarVC.tabBar.barTintColor =[Uicolor Orangecolor];

TabBarVC.tabBar.tintColor = [Uicolor Greencolor];

TabBarVC.tabBar.backgroundImage = [UIImage imagenamed:@ "TABBG"];

5.7 Setting the related properties of Tabbaritem

Render with the original picture

UIImage *firstimg =[[uiimage imagenamed:@ "Tab_0"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

Firstvc.tabbaritem = [[Uitabbaritem alloc]initwithtitle:@ "First page" Image:firstimg Tag:1];

Secondvc.tabbaritem = [[Uitabbaritem alloc]initwithtitle:@ "Second" Image:[uiimage imagenamed:@ "tab_1"] selectedImage : [UIImage imagenamed:@ "tab_2"];

SecondVC.tabBarItem.badgeValue = @ "10"; Reminder numbers

Ui-uinavigationcontroller Uitabbarcontroller Use Summary

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.