First, 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, Weibo, etc. should be?
Second, the use of Uitabbarcontroller
1, first initialize the Uitabbarcontroller
2, set UIWindow Rootviewcontroller for Uitabbarcontroller
3. Create the appropriate sub-controller (Viewcontroller)
4. Add the controller to the Uitabbarcontroller
Code:
////APPDELEGATE.M// ////Created by Oran Wu on 15-11-5.//Copyright (c) 2015 xinxin. All rights reserved.//#import "AppDelegate.h"#import "WeChatViewController.h"#import "AddressBookViewController.h"#import "FindViewController.h"#import "MyViewController.h"@interfaceappdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {//Create WindowSelf.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; //Create a child controllerWechatviewcontroller *WECHATVC =[[Wechatviewcontroller alloc] init]; Addressbookviewcontroller*ADDRESSBOOKVC =[[Addressbookviewcontroller alloc] init]; Findviewcontroller*FINDVC =[[Findviewcontroller alloc] init]; Myviewcontroller*MYVC =[[Myviewcontroller alloc] init]; //set Uitabbarbutton picture (normal) and picture when selected (selected)UIImage *wechatimage = [UIImage imagenamed:@"Tabbar_mainframe"]; UIImage*wechatseletedimage = [UIImage imagenamed:@"Tabbar_mainframehl"]; Wechatvc.tabbaritem= [[Uitabbaritem alloc] Initwithtitle:@""Image:wechatimage Selectedimage:wechatseletedimage]; UIImage*addressimage = [UIImage imagenamed:@"tabbar_contacts"]; UIImage*addressseletedimage = [UIImage imagenamed:@"TABBAR_CONTACTSHL"]; Addressbookvc.tabbaritem= [[Uitabbaritem alloc] Initwithtitle:@"Contacts"Image:addressimage Selectedimage:addressseletedimage]; UIImage*fineimage = [UIImage imagenamed:@"Tabbar_discover"]; UIImage*fineseletedimage = [UIImage imagenamed:@"TABBAR_DISCOVERHL"]; Findvc.tabbaritem= [[Uitabbaritem alloc] Initwithtitle:@"found"Image:fineimage Selectedimage:fineseletedimage]; //Reminder numbers
FindVC.tabBarItem.badgeValue=@"1"; UIImage*myimage = [UIImage imagenamed:@"Tabbar_me"]; UIImage*myseletedimage = [UIImage imagenamed:@"Tabbar_mehl"]; Myvc.tabbaritem= [[Uitabbaritem alloc] Initwithtitle:@"I'm"Image:myimage Selectedimage:myseletedimage]; //initializing the navigation controllers for each ViewcontrollerUinavigationcontroller *wechatnav =[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:WECHATVC]; Uinavigationcontroller*addressbooknav =[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:ADDRESSBOOKVC]; Uinavigationcontroller*findnav =[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:FINDVC]; Uinavigationcontroller*mynav =[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:MYVC]; //Initialize a controllerUitabbarcontroller *tabbarctrl =[[Uitabbarcontroller alloc] init]; Tabbarctrl.viewcontrollers=[Nsarray Arraywithobjects:wechatnav,addressbooknav,findnav,mynav, Nil]; //set the Controller as window's root controllerSelf.window.rootViewController =Tabbarctrl; //set the background color of a windowSelf.window.backgroundColor =[Uicolor Whitecolor]; //Set window as the main window and display it[Self.window makekeyandvisible]; //Override point for customization after application launch. returnYES;}
Third, 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:
iOS Basics (eight) a brief introduction to--uitabbarcontroller