UI Advanced--uitabbarcontroller Simple Introduction

Source: Internet
Author: User

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

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.