iOS Development Uitabbarcontroller

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.