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
TXAPPDELEGATE.M file
1 #import "TXAppDelegate.h"2 3 @implementationtxappdelegate4 5-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions6 {7Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];8 //Override point for customization after application launch.9Self.window.backgroundColor =[Uicolor Whitecolor];Ten One //1. Create a Tabbar controller AUitabbarcontroller *TABBARVC =[[Uitabbarcontroller alloc] init]; - - //2. The root controller set to window theSelf.window.rootViewController =TABBARVC; - - //3. Adding a child controller -Uiviewcontroller *VC1 =[[Uiviewcontroller alloc] init]; +Vc1.view.backgroundColor =[Uicolor Redcolor]; -Vc1.tabBarItem.title =@"Contact Person"; +Vc1.tabBarItem.image = [UIImage imagenamed:@"Tab_buddy_nor"]; A //[TABBARVC ADDCHILDVIEWCONTROLLER:VC1]; at -Uiviewcontroller *VC2 =[[Uiviewcontroller alloc] init]; -Vc2.view.backgroundColor =[Uicolor Bluecolor]; -Vc2.tabBarItem.title =@"Dynamic"; -Vc2.tabBarItem.image = [UIImage imagenamed:@"Tab_qworld_nor"]; - //[TABBARVC ADDCHILDVIEWCONTROLLER:VC2]; in -Uiviewcontroller *VC3 =[[Uiviewcontroller alloc] init]; toVc3.view.backgroundColor =[Uicolor Greencolor]; +Vc3.tabBarItem.title =@"Set"; -Vc3.tabBarItem.image = [UIImage imagenamed:@"Tab_me_nor"]; the //[TABBARVC ADDCHILDVIEWCONTROLLER:VC3]; * $Tabbarvc.viewcontrollers =@[vc1, VC2, VC3];Panax Notoginseng - [Self.window makekeyandvisible]; the returnYES; +}
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.
iOS Development UI Chapter-uitabbarcontroller Brief Introduction