Uitabbarcontroller similar to Uinavigationcontroller, Uitabbarcontroller can easily manage multiple controllers, easily switch between controllers, the typical example is QQ, and other applications. Uitabbarcontroller also said in a brief introduction, in order to facilitate the management of the Controller, iOS provides 2 more special controllers: Uitabbarcontroller controller and Uinavigationcontroller controller. Uitabbarcontroller There are 2 ways to add a controller: Add a single sub-controller:
-(void) Addchildviewcontroller: (Uiviewcontroller *) Childcontroller;
To set up a sub-controller array:
Property (nonatomic,copy) Nsarray *viewcontrollers;
What is displayed inside the Uitabbarbutton, determined by the Tabbaritem property of the corresponding sub-controller Uitabbaritem has the following properties affecting the contents of the Uitabbarbutton
1 // Title Text 2 @property (nonatomic,copy) NSString *title; 3 // icons 4 @property (nonatomic,retain) UIImage *image; 5 // icon When selected 6 @property (nonatomic,retain) UIImage *selectedimage; 7 // Reminder Numbers 8 @property (nonatomic,copy) NSString *badgevalue;
Specific sample code (in the APPDELEGATE.M file):
1 //1. Create a window2UIWindow *window =[[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];3 4 //2. Set the window's root controller to the Tabbar controller5 6 //2.1 Creating a Tabbar controller7Uitabbarcontroller *TABBARVC =[[Uitabbarcontroller alloc] init];8 9 //2.2 Setting up the sub-controllerTenUiviewcontroller *VC1 =[[Uiviewcontroller alloc] init]; OneVc1.view.backgroundColor =[Uicolor Redcolor]; A - //set the title of the Uitabbarbutton -Vc1.tabBarItem.title =@"Contact Person"; theVc1.tabBarItem.image = [UIImage imagenamed:@"Tab_buddy_nor"]; -Vc1.tabBarItem.badgeValue =@ " a"; - //[TABBARVC ADDCHILDVIEWCONTROLLER:VC1]; - +Uiviewcontroller *VC2 =[[Uiviewcontroller alloc] init]; -Vc2.view.backgroundColor =[Uicolor Greencolor]; + //[TABBARVC ADDCHILDVIEWCONTROLLER:VC2]; AVc2.tabBarItem.title =@"Dynamic"; atVc2.tabBarItem.image = [UIImage imagenamed:@"Tab_qworld_nor"]; - - -Uiviewcontroller *VC3 =[[Uiviewcontroller alloc] init]; -Vc3.view.backgroundColor =[Uicolor Yellowcolor]; - //[TABBARVC ADDCHILDVIEWCONTROLLER:VC3]; inVc3.tabBarItem.title =@"Set"; -Vc3.tabBarItem.image = [UIImage imagenamed:@"Tab_me_nor"]; to + - //adding Tabbar sub-controllers at once theTabbarvc.viewcontrollers =@[vc1,vc2,vc3]; * //setting the root controller of a window $Window.rootviewcontroller =TABBARVC;Panax Notoginseng - //3. Set the window as the main window and visible the [window makekeyandvisible]; +Self.window = window;
Final effect:
UI Advanced--uitabbarcontroller Simple Introduction