First, Uitabbarcontroller use detailed
Uitabbarcontroller is a very common viewcontroller in iOS, such as the system's alarm clock programs, ipod programs, and so on. Uitabbarcontroller are usually rootviewcontroller for the entire program and cannot be added to other container viewcontroller.
First, let's take a look at its view level graph:
Second, manually create Uitabbarcontroller
The most common place to create Uitabbarcontroller is the applicationdidfinishlaunching in the application delegate : Method, Since Uitabbarcontroller is usually the rootviewcontroller of the entire program, we need to create it before the window of the program is displayed, in the following steps:
1. Initialize Uitabbarcontroller
// Initialize Uitabbarcontroller Uitabbarcontroller *tabbarcon=[[uitabbarcontroller alloc] init];
2, create the Tabbarcontroller in each tab corresponding to the object to be displayed, that is, the child view
Hhfirstviewcontroller *first=[[hhfirstviewcontroller alloc] Initwithnibname:@ "hhfirstviewcontroller [ bundle:nil]; *firstnav=[[uinavigationcontroller alloc] Initwithrootviewcontroller:first];
3. Add tab-corresponding objects to Uitabbarcontroller
// to add an object to the Tabbarcon [Tabbarcon Setviewcontrollers:@[firstnav,secondnav,threenav]];
4. By setting the Uitabbarcontroller object to Window.rootviewcontroller, and then displaying the window
self.window.rootviewcontroller=Tabbarcon; [Self.window makekeyandvisible];
Based on the above 4 steps, the creation of Uitabbarcontroller is basically complete, but it does not meet our normal development, but also involves some basic properties.
Three, Uitabbarcontroller basic properties
1. Set the title of Tabbar.
@property (nonatomic,copy) nsstring *title; // default is nil
2. Set the constant picture
@property (nonatomic,retain) UIImage *image; // default is nil
3. Set up a high volume picture
@property (nonatomic,retain) UIImage *selectedimage Ns_available_ios (7_0);
4. Set the font color of the selected Tabbar
/* Selectedimagetintcolor'll is applied to the gradient image used when creating the selected image. Default is nil and would result in the system bright blue for selected tab item images. If you wish to also customize the unselected image appearance, you must use the image and SelectedImage properties on Uita Bbaritem along with uiimagerenderingmodealways */*selectedimagetintcolor ns_deprecated_ IOS (5_0,8_0,"usetintcolor") Ui_appearance_selector;
By completing these 4 properties, our Uitabbarcontroller can be completely basic in function. Such as:
Here is all the code for creating Uitabbarcontroller:
self.window=[[UIWindow alloc]initwithframe:[[uiscreen mainscreen] bounds]; Hhfirstviewcontroller*first=[[hhfirstviewcontroller Alloc] Initwithnibname:@"Hhfirstviewcontroller"Bundle:nil]; Uinavigationcontroller*firstnav=[[Uinavigationcontroller alloc] initwithrootviewcontroller:first]; Hhsecondviewcontroller*second=[[hhsecondviewcontroller Alloc] Initwithnibname:@"Hhsecondviewcontroller"Bundle:nil]; Uinavigationcontroller*secondnav=[[Uinavigationcontroller Alloc]initwithrootviewcontroller:second]; Hhthreeviewcontroller*three=[[hhthreeviewcontroller Alloc] Initwithnibname:@"Hhthreeviewcontroller"Bundle:nil]; Uinavigationcontroller*threenav=[[Uinavigationcontroller alloc] initwithrootviewcontroller:three]; //Initialize UitabbarcontrollerUitabbarcontroller *tabbarcon=[[Uitabbarcontroller alloc] init]; //to add an object to the Tabbarcon[Tabbarcon Setviewcontrollers:@[firstnav,secondnav,threenav]]; TabbarCon.tabBar.selectedImageTintColor=[uicolor Orangecolor];//Set the selected font colorUitabbar*tabbar=Tabbarcon.tabbar; Uitabbaritem*itemfirst=[tabbar.items Objectatindex:0]; Itemfirst.title=@"Excellent loan -to-pass"; Uitabbaritem*itemsecond=[tabbar.items Objectatindex:1]; Itemsecond.title=@"Personal Center"; Uitabbaritem*itemthree=[tabbar.items Objectatindex:2]; Itemthree.title=@"more"; //set a constant pictureItemfirst.image=[[uiimage imagenamed:@"Merchant _normol.png"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; //Set the selected pictureItemfirst.selectedimage=[[uiimage imagenamed:@"Merchant _press.png"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Itemsecond.image=[[uiimage imagenamed:@"my _normol.png."] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Itemsecond.selectedimage=[[uiimage imagenamed:@"my _press."] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Itemthree.image=[[uiimage imagenamed:@"more _normol.png"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Itemthree.selectedimage=[[uiimage imagenamed:@"more _press.png"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Self.window.rootViewController=Tabbarcon; [Self.window makekeyandvisible];
View Code
Note: The position of Uitabbarbutton in Uitabbar is evenly divided, the height of Uitabbar is 49. The size of the icon is 30, or equal to the scale.
Easy use of IOS Uitabbarcontroller