Transfer Uitabbarcontroller Brief Introduction

Source: Internet
Author: User

Text top-top iOS Development UI Chapter-uitabbarcontroller Brief Introduction

iOS Development UI Chapter-uitabbarcontroller Brief Introduction

First, Brief introduction

Uitabbarcontroller and Uinavigationcontroller Similar, Uitabbarcontroller can also easily manage multiple controllers, easy to complete the switch between the controller, the typical example is QQ, etc.

Second, the use of Uitabbarcontroller

1. Steps to use:

(1) Initialize Uitabbarcontroller

(2) Set UIWindow Rootviewcontroller to Uitabbarcontroller

(3) Create the appropriate sub-controller (Viewcontroller)

(4) Add the controller to the Uitabbarcontroller

2. Code examples

Create a new empty file, encode it in the proxy of application

YYAPPDELEGATE.M file

1//2//Yyappdelegate.m3//01-uitabbar Controller Basic Use4//5//Created by Hole Medical has on 14-6-7.6//Copyright (c) 2014 itcast. All rights reserved.7//89#import"YYAppDelegate.h"1011@implementationYyappdelegate12-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions14{15//1. Create windowSelf.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];Self.window.backgroundColor =[Uicolor Whitecolor];1819//A. Initializing a Tabbar controllerUitabbarcontroller *tb=[[Uitabbarcontroller Alloc]init];21st//Set the Controller as window's root controllerSelf.window.rootviewcontroller=Tb2324//B. Creating a sub-controllerUiviewcontroller *c1=[[Uiviewcontroller Alloc]init];C1.view.backgroundcolor=[Uicolor Graycolor];C1.view.backgroundcolor=[Uicolor Greencolor];c1.tabbaritem.title=@"News";C1.tabbaritem.image=[uiimage imagenamed:@"Tab_recent_nor"];C1.tabbaritem.badgevalue=@"123";31Uiviewcontroller *c2=[[Uiviewcontroller Alloc]init];C2.view.backgroundcolor=[Uicolor Browncolor];c2.tabbaritem.title=@"Contact";C2.tabbaritem.image=[uiimage imagenamed:@"Tab_buddy_nor"];36Panax Notoginseng Uiviewcontroller *c3=[[Uiviewcontroller Alloc]init];c3.tabbaritem.title=@"Dynamic";C3.tabbaritem.image=[uiimage imagenamed:@"Tab_qworld_nor"];40Uiviewcontroller *c4=[[Uiviewcontroller Alloc]init];c4.tabbaritem.title=@"Set up";C4.tabbaritem.image=[uiimage imagenamed:@"Tab_me_nor"];444546//C. Adding a sub-controller to Itabbarcontroller47//The first way of C.148//[TB ADDCHILDVIEWCONTROLLER:C1];49// [TB ADDCHILDVIEWCONTROLLER:C2]; 50 51 //c.2 the second way 52 tb.viewcontrollers=@[c1,c2,c3,c4];53 54 55 //2. Set window as the main window and display it 56  [Self.window Makekeyandvisible]; 57 return Yes;58 }59 60  @end                 

Implementation results:

Iii. Important Notes

1.UITabBar

The toolbar below is called Uitabbar, and if the Uitabbarcontroller has n sub-controllers, there will be N Uitabbarbutton as child controls within the Uitabbar.

Note: The position of Uitabbarbutton in Uitabbar is evenly divided, and the height of Uitabbar is 49.

In the above program, Uitabbarcontroller has 4 sub-controllers, so there are 4 uitabbarbutton,uitabbar structures in the Uitabbar, as shown here:

2.UITabBarButton

Uitabbarbutton? What content is determined by the Tabbaritem attribute of the corresponding sub-controller

c1.tabbaritem.title=@ " message "; C1.tabbaritem.image=[uiimage imagenamed:@ "tab_recent_nor"];      

3. There are two ways to add a sub-controller to the Uitabbarcontroller

(1)[TB ADDCHILDVIEWCONTROLLER:C1];

(2)[email protected][c1,c2,c3,c4];

Note: The order of presentation is the same as the order of addition, unlike the navigation controller, which is displayed in front of the view that corresponds to the first added controller.

Transfer Uitabbarcontroller Brief 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.