"iOS Dev-28" process for manufacturing Uitabbarcontroller tag controllers and 6 ways to customize Uitabbaritem text images

Source: Internet
Author: User

One simple creation process (actual project does not recommend this way, only to do demonstration understanding principle)


In the APPDELEGATE.M:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {//    Create one to the navigation controller Uiviewcontroller *vc1=[[uiviewcontroller Alloc]init];    Uinavigationcontroller *nav1=[[uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:VC1];    [email protected] "home";    Create three view controllers Uiviewcontroller *vc2=[[uiviewcontroller Alloc]init];    [Email protected] "collection";    Uiviewcontroller *vc3=[[uiviewcontroller Alloc]init];    [email protected] "search";    Uiviewcontroller *vc4=[[uiviewcontroller Alloc]init];    [email protected] "settings";    Create an array put the above 1 navigation controllers and 3 View controller instances in the Nsarray *arr1=[[nsarray Alloc]initwithobjects:nav1,vc2,vc3,vc4, nil]; First instantiate a uitabbarcontroller, then assign the above array to its Viewcontrollers property Uitabbarcontroller *tb1=[[uitabbarcontroller Alloc]    INIT];    TB1.VIEWCONTROLLERS=ARR1; The most important thing is to assign the tag controller above to the Self.window Rootviewcontroller, so that it can be displayed, and the previous navigation controller display is the same self.window.rootviewcontroller=tb1    ; Override Point for CustOmization after application launch. return YES;}

Operating effect:


Second, the matters needing attention


(1) The above directly assigns the array to the Viewcontrollers property of the tag controller instance. And generally do not do the project, the above is just the process of demonstrating the implementation of the whole principle.


(2) Uitabbarcontroller has two sub-views, one is the uitabbar part, it is placed Uitabbaritem is the following four switch tag that piece. The other is the content part, which is a few views. When we click on a different tab, we switch to show different views. So if we load the view controller, we might be making changes to the view. The custom label, however, is modified for Uitabbaritem.


(3) Size, Uitabbaritem has the picture icon also has the text, the picture is 50*50. For specific parameters, click here.


Three, Uitabbaritem property introduction and 6 ways to create


We created 6 view controllers and then imported their header files, so in the APPDELEGATE.M file:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {//    The first way: The Image property is called by the Tabbaritem of the navigation controller Viewcontroller *vc0=[[viewcontroller Alloc]init];    Uinavigationcontroller *nav0=[[uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:VC0]; Use [email protected] "interface 1"; To assign a value to the caption, the value of the. Title is not available,//The caption is assigned in the following way,    You can use the. Tabbaritem.title value, but the following way directly to the Navigationitem.title also assigned value//priority to use the following method [email protected] "interface 1";        Assignment picture Nav0.tabbaritem.image=[uiimage imagenamed:@ "[email protected]"]; The second way: Using the Setfinishedselectedimage method with the Tabbaritem of the view controller, set the unselected picture state to selected//But this method seems not recommended to use, in the iOS7 has been discarded//    So it is recommended to use InitWithTitle:image:selectedImage: This initialization method ViewController1 *vc1=[[viewcontroller1 Alloc]init];    [email protected] "Interface 2"; [Vc1.tabbaritem setfinishedselectedimage:[uiimage imagenamed:@ "[email protected]"]    Withfinishedunselectedimage:[uiimage imagenamed:@ "[email protected]"]; Uitabbaritem *tb0=[[Uitabbaritem alloc]initwithtitle:@ "Interface 2" Image:[uiimage imagenamed:@ "[email protected]"] selectedImage:[    UIImage imagenamed:@ "[email protected]"];        vc1.tabbaritem=tb0;    The third Way: Call the Image property via the Tabbaritem of the View controller ViewController2 *vc2=[[viewcontroller2 Alloc]init];    [email protected] "Interface 3";        Vc2.tabbaritem.image=[uiimage imagenamed:@ "[email protected]"];    Fourth Way: Set the logo, Badgevalue is a property of Tabbaritem, the value is the string ViewController3 *vc3=[[viewcontroller3 Alloc]init];    [email protected] "Interface 4";    Vc3.tabbaritem.image=[uiimage imagenamed:@ "[email protected]"];        [email protected] "6";    The fifth way: by first setting up a system to bring the Uitabbaritem, and then assign it to the View controller Tabbaritem//created in this way, then set. Title or. Tabbaritem.image doesn't work.    ViewController4 *vc4=[[viewcontroller4 Alloc]init];    Uitabbaritem *tb1=[[uitabbaritem alloc]initwithtabbarsystemitem:uitabbarsystemitemfavorites tag:0];        VC4.TABBARITEM=TB1; The sixth way: by first initializing a uitabbaritem with a caption and a picture, and then assigning it to the View controller's Tabbaritem//equal to the respective pair. tiTle and. Tabbaritem.image settings, the effect is similar//this way is not recommended to use VIEWCONTROLLER5 *vc5=[[viewcontroller5 alloc]init]; Uitabbaritem *tb2=[[uitabbaritem alloc]initwithtitle:@ "interface 6" Image:[uiimage imagenamed:@ "[email protected]"]    TAG:1];        VC5.TABBARITEM=TB2; Here is the whole number of the assembly above, and then initialize a uitabbarcontroller and then assign the array to the Uitabbarcontroller viewcontrollers attribute//finally don't forget,    Modify the window's root view controller Nsarray *arr2=[[nsarray alloc]initwithobjects:nav0,vc4,vc1,vc3,vc2,vc5, nil];    Uitabbarcontroller *tbcon1=[[uitabbarcontroller Alloc]init];    TBCON1.VIEWCONTROLLERS=ARR2;        Self.window.rootviewcontroller=tbcon1;    Override point for customization after application launch. return YES;}

(1) Tabbar icon can only display 5, more than 5 are all co-located to more inside, this more system comes with the icon.


(2) Mainly by two ways: one is directly in the use of the existing navigation controller or view controller. Title and. Tabbaritem.image properties to set text and pictures. Another is to create a uitabbaritem (the text is not selected picture selected pictures, etc.) and then assign this uitabbaritem to the navigation controller or the view controller's. Tabbaritem property.


(3) It is recommended to use the second method, because it can be created Uitabbaritem when the text, selected pictures, unselected pictures and other different states are defined.


"iOS Dev-28" process for manufacturing Uitabbarcontroller tag controllers and 6 ways to customize Uitabbaritem text images

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.