iOS Development UI Chapter-uitabbarcontroller Brief Introduction
First, Brief introduction
Uitabbarcontroller and Uinavigationcontroller Similar, Uitabbarcontroller can also easily manage multiple controllers, easy to complete the switch between the controller, the typical example is QQ, etc.
Second, the use of Uitabbarcontroller
1. Steps to use:
(1) Initialize Uitabbarcontroller
(2) Set UIWindow Rootviewcontroller to Uitabbarcontroller
(3) Create the appropriate sub-controller (Viewcontroller)
(4) Add the controller to the Uitabbarcontroller
2. Code examples
Create a new empty file, encode it in the proxy of application
YYAPPDELEGATE.M file
////YYAPPDELEGATE.M//01-uitabbar Controller Basic use////Created by Hole Medical has on 14-6-7.//Copyright (c) 2014 itcast. All rights reserved.//#import"YYAppDelegate.h"@implementation yyappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions{//1. Create WindowSelf.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; Self.window.backgroundColor=[Uicolor Whitecolor]; //A. Initializing a Tabbar controllerUitabbarcontroller *tb=[[Uitabbarcontroller alloc]init]; //set the Controller as window's root controllerSelf.window.rootviewcontroller=TB; //B. Creating a sub-controllerUiviewcontroller *c1=[[Uiviewcontroller alloc]init]; C1.view.backgroundColor=[Uicolor Graycolor]; C1.view.backgroundColor=[Uicolor Greencolor]; C1.tabBarItem.title=@"message"; C1.tabBarItem.image=[uiimage imagenamed:@"Tab_recent_nor"]; C1.tabBarItem.badgeValue=@"123"; Uiviewcontroller*c2=[[Uiviewcontroller alloc]init]; C2.view.backgroundColor=[Uicolor Browncolor]; C2.tabBarItem.title=@"Contact Person"; C2.tabBarItem.image=[uiimage imagenamed:@"Tab_buddy_nor"]; Uiviewcontroller*c3=[[Uiviewcontroller alloc]init]; C3.tabBarItem.title=@"Dynamic"; C3.tabBarItem.image=[uiimage imagenamed:@"Tab_qworld_nor"]; Uiviewcontroller*c4=[[Uiviewcontroller alloc]init]; C4.tabBarItem.title=@"Set"; C4.tabBarItem.image=[uiimage imagenamed:@"Tab_me_nor"]; //C. Adding a sub-controller to Itabbarcontroller//The first way of C.1//[TB ADDCHILDVIEWCONTROLLER:C1];//[TB ADDCHILDVIEWCONTROLLER:C2]; //C.2 Second Waytb.viewcontrollers=@[c1,c2,c3,c4]; //2. Set the window to be the primary and display it[Self.window makekeyandvisible]; returnYES;} @end
Implementation results:
Iii. Important Notes
1.UITabBar
The toolbar below is called Uitabbar, and if the Uitabbarcontroller has n sub-controllers, there will be N Uitabbarbutton as child controls within the Uitabbar.
Note: The position of Uitabbarbutton in Uitabbar is evenly divided, and the height of Uitabbar is 49.
In the above program, Uitabbarcontroller has 4 sub-controllers, so there are 4 uitabbarbutton,uitabbar structures in the Uitabbar, as shown here:
2.UITabBarButton
Uitabbarbutton? What content is determined by the Tabbaritem attribute of the corresponding sub-controller
c1.tabbaritem.title=@ " message "; C1.tabBarItem.image=[uiimage imagenamed:@ "tab_recent_nor"];
3. There are two ways to add a sub-controller to the Uitabbarcontroller
(1) [TB ADDCHILDVIEWCONTROLLER:C1];
(2) [email PROTECTED][C1,C2,C3,C4];
Note: The order of presentation is the same as the order of addition, unlike the navigation controller, which is displayed in front of the view that corresponds to the first added controller.
iOS Development UI Chapter-uitabbarcontroller Brief Introduction