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
1//2//YYAPPDELEGATE.M 3//01-uitabbar Controller Basic use 4//5//Created by hole Medical self on 14-6-7. 6//Copyright (c) 2014 itcast. All rights reserved. 7//8 9 #import "YYAppDelegate.h" @implementation YYAppDelegate12-(BOOL) Application: (UIApplication *) Applicati On didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions14 {15//1. Create Window16 Self.window = [[UIWindow alloc ] Initwithframe:[[uiscreen Mainscreen] bounds]];17 self.window.backgroundColor = [Uicolor whitecolor];18 19// A. Initializing a Tabbar controller Uitabbarcontroller *tb=[[uitabbarcontroller alloc]init];21//Setting the Controller to the window's root controller, Self.windo W.rootviewcontroller=tb;23//b. Create a sub-controller Uiviewcontroller *c1=[[uiviewcontroller alloc]init];26 c1.view. Backgroundcolor=[uicolor graycolor];27 c1.view.backgroundcolor=[uicolor greencolor];28 [email protected] "message"; C1.tabbaritem.image=[uiimage imagenamed:@ "Tab_recent_nor"];30 [email protected] "123"; UIViewC ONtroller *c2=[[uiviewcontroller alloc]init];33 c2.view.backgroundcolor=[uicolor brownColor];34 [email protect ED] "Contact"; C2.tabbaritem.image=[uiimage imagenamed:@ "Tab_buddy_nor"];36 Notoginseng uiviewcontroller *c3=[[uiviewcontr Oller alloc]init];38 [email protected] "dynamic"; C3.tabbaritem.image=[uiimage imagenamed:@ "Tab_qworld_nor"];40 Uiviewcontroller *c4=[[uiviewcontroller alloc]init];42 [email protected] "settings"; c4.tabBarItem.image =[uiimage imagenamed:@ "Tab_me_nor"];44,//c. Adding a sub-controller to Itabbarcontroller the first method of//C.1//[TB Addchil dviewcontroller:c1];49//[TB addchildviewcontroller:c2];50 Wuyi//c.2 Second Way [email protected][c1,c2,c3 , c4];53 54 55//2. Set the window to be the primary and display the [Self.window makekeyandvisible];57 return yes;58}59 @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
[Email protected] "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.
Introduction to Objective-c learning-uitabbarcontroller