1 , overview
Similar to Uinavigationcontroller, Uitabbarcontroller can easily manage multiple controllers, easily switch between controllers, typical examples are QQ, and other applications.
2 , Uitabbarcontroller the simple use
Uitabbarcontroller Steps to use:
(1) Initialize Uitabbarcontroller
(2) Set UIWindow Rootviewcontroller to Uitabbarcontroller
(3) According to the specific situation, add the corresponding number of sub-controller by Addchildviewcontroller method
3 , Uitabbarcontroller the child controller
There are 2 ways to add controllers Uitabbarcontroller:
(1) Adding a single sub-controller
-(void) Addchildviewcontroller: (Uiviewcontroller *) Childcontroller;
(2) Set the sub-controller array
@property (nonatomic,copy) Nsarray *viewcontrollers;
(3) Select sub-controller according to index
Self.selectedindex = 0;//Select No. 0 sub-controller
4 , Uitabbar
If the Uitabbarcontroller has n sub-controllers, there will be N Uitabbarbutton as child controls inside the Uitabbar.
For example, if the Uitabbarcontroller has 4 sub-controllers, the structure of the Uitabbar is roughly as follows:
5 , Uitabbarbutton
What is displayed inside the Uitabbarbutton is determined by the Tabbaritem property of the corresponding sub-controller :
For example:
Uiviewcontroller *VC1 = [[Uiviewcontroller alloc] init];
Vc1.tabBarItem.title = @ "Contact";
Vc1.tabBarItem.image = [UIImage imagenamed:@ "Tab_buddy_nor"];
Click Related Tabbaritem , the system automatically turns the button into blue and does not need to provide a blue button picture. You can also set a picture to be displayed after a click by calling the SelectedImage method.
For example:
ChildVc.tabBarItem.selectedImage =
[[UIImage Imagenamed:selectedimagename]
Imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];
IOS7 The render mode must be set to not render, or it will turn blue when selected. IOS6 not set. However , IOS6 does not have this method, so use this method before using the system version to divide the situation. For example:
#define IOS7 ([[Uidevice currentdevice].systemversion Doublevalue] >= 7.0)
if (iOS7) {
ChildVc.tabBarItem.selectedImage = [SelectedImage imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];
} else {
ChildVc.tabBarItem.selectedImage = SelectedImage;
}
You can also drag a uitabbarcontrollerview past in storyboard, then right-select the View controllers drag line to the child controller to add a child controller, such as:
6 , App mainstream UI Frame Structure
7. Modal
In addition to push, there is another kind of controller switching mode, that is modal. any controller can pass Modal form to show . Modal default effect: The new controller drills up from the bottom of the screen until it covers the previous controller.
in Modal form of display controller:
-(void) Presentviewcontroller: (Uiviewcontroller *) viewcontrollertopresent animated: (BOOL) flag completion: (void (^) ( void)) Completion
For example:
Mjtwoviewcontroller *two = [[Mjtwoviewcontroller alloc] init];
[Self presentviewcontroller:two animated:yes completion:^{
NSLog (@ "show Mjtwoviewcontroller finished ...");//display will call
}];
Close the original Modal out of the controller:
-(void) dismissviewcontrolleranimated: (BOOL) flag completion: (void (^) (void)) completion;
For example:
[Self Dismissviewcontrolleranimated:yes completion:^{
NSLog (@ "Close mjtwoviewcontroller ...");//will execute after closing
}];
iOS Development Uitabbarcontroller