iOS Development UI Chapter-uitabbarcontroller Brief Introduction

Source: Internet
Author: User

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 //8 9 #import "YYAppDelegate.h"Ten  One @implementationyyappdelegate A  --(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions - { the     //1. Create Window -Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; -Self.window.backgroundColor =[Uicolor Whitecolor]; -      +     //A. Initializing a Tabbar controller -Uitabbarcontroller *tb=[[Uitabbarcontroller alloc]init]; +     //set the Controller as window's root controller ASelf.window.rootviewcontroller=TB; at      -     //B. Creating a sub-controller -Uiviewcontroller *c1=[[Uiviewcontroller alloc]init]; -C1.view.backgroundcolor=[Uicolor Graycolor]; -C1.view.backgroundcolor=[Uicolor Greencolor]; -c1.tabbaritem.title=@"message"; inC1.tabbaritem.image=[uiimage imagenamed:@"Tab_recent_nor"]; -C1.tabbaritem.badgevalue=@"123"; to      +Uiviewcontroller *c2=[[Uiviewcontroller alloc]init]; -C2.view.backgroundcolor=[Uicolor Browncolor]; thec2.tabbaritem.title=@"Contact Person"; *C2.tabbaritem.image=[uiimage imagenamed:@"Tab_buddy_nor"]; $     Panax NotoginsengUiviewcontroller *c3=[[Uiviewcontroller alloc]init]; -c3.tabbaritem.title=@"Dynamic"; theC3.tabbaritem.image=[uiimage imagenamed:@"Tab_qworld_nor"]; +      AUiviewcontroller *c4=[[Uiviewcontroller alloc]init]; thec4.tabbaritem.title=@"Set"; +C4.tabbaritem.image=[uiimage imagenamed:@"Tab_me_nor"]; -     $      $     //C. Adding a sub-controller to Itabbarcontroller -     //The first way of C.1 - //[TB ADDCHILDVIEWCONTROLLER:C1]; the //[TB ADDCHILDVIEWCONTROLLER:C2]; -     Wuyi     //C.2 Second Way thetb.viewcontrollers=@[c1,c2,c3,c4]; -      Wu      -     //2. Set the window to be the primary and display it About [Self.window makekeyandvisible]; $     returnYES; - } -  - @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

[Email protected] "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.

iOS Development UI Chapter-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.