"Learning the path to iOS: UI series" Uitabbarcontroller, Uitoorbar

Source: Internet
Author: User

1. uitabbarcontroller(Tag view controller), used to manage the view controller with side-by-side relationship, multiple interfaces exist simultaneously.

Uitablebarcontroller and Uinavigationcontroller similar, Uitabbarcontroller It is also easy to manage multiple controllers to easily switch between controllers, and a typical example is QQ , etc.?. Effects such as:


① Use the Uitabbarcontroller steps as follows:
(1) Initialize Uitabbarcontroller
(2) Set UIWindow Rootviewcontroller to Uitabbarcontroller
(3) Create the appropriate sub-controller (Viewcontroller)
(4) Add the controller to the Uitabbarcontroller

Implement the above effect code as follows:

    Create the first attempt controller firstviewcontroller *FIRSTVC = [[Firstviewcontroller alloc] init];    Set Barbutton title  firstvc.tabbaritem.title = @ "message";    Corner Mark FirstVc.tabBarItem.badgeValue = @ "new";    Set the picture when selected first Vc.tabBarItem.selectedImage = [UIImage imagenamed:@ "tabbar_contacts"];    Set Picture  firstvc.tabbaritem.image = [UIImage imagenamed:@ "Tabbar_mainframe"]; FirstVc.tabBarItem.tag = 100;//Set tag//create a second controller secondviewcontroller *SECONDVC = [[Secondviewcontroller alloc] I    NIT];    SecondVc.tabBarItem.title = @ "in communication";    When the picture is selected SecondVc.tabBarItem.selectedImage = [UIImage imagenamed:@ "Tabbar_discover"];    SecondVc.tabBarItem.badgeValue = @ "33";    SecondVc.tabBarItem.tag = 101;    Modify the position of the font [Secondvc.tabbaritem settitlepositionadjustment:uioffsetmake (-1,-1)];    SecondVc.tabBarItem.image = [UIImage imagenamed:@ "tabbar_contacts"];    A third  thirdviewcontroller *THIRDVC = [[Thirdviewcontroller alloc] init]; ThirdVc.tabBarItem.title = @ "Discovery";    ThirdVc.tabBarItem.tag = 102;    ThirdVc.tabBarItem.badgeValue = @ "2";    ThirdVc.tabBarItem.image = [UIImage imagenamed:@ "Tabbar_discover"];    ThirdVc.tabBarItem.selectedImage = [UIImage imagenamed:@ "Tabbar_me.png"];    Fourth  foursviewcontroller *fourvc = [[Foursviewcontroller alloc] init];    FourVc.tabBarItem.title = @ "my";    FourVc.tabBarItem.tag = 103;    FourVc.tabBarItem.image = [UIImage imagenamed:@ "Tabbar_me.png"];    FourVc.tabBarItem.badgeValue = @ "88";        FourVc.tabBarItem.selectedImage = [UIImage imagenamed:@ "Tabbar_discover"];    Fifth Fifthviewcontroller *FIFTHVC = [[Fifthviewcontroller alloc] init];    FifthVC.tabBarItem.title = @ "Download";         FifthVC.tabBarItem.image = [UIImage imagenamed:@ "Qr_toolbar_online_download_hl"];    Sixth Sixviewcontroller *SIXVC = [[Sixviewcontroller alloc] init];    SixVc.tabBarItem.title = @ "Tool";        SixVc.tabBarItem.image = [UIImage imagenamed:@ "Qr_toolbar_light_up_hl"]; When the label view Controller manages more than 5 view controllers. tab bar The Fifth tab automatically becomes aMore (more) tags,   In addition to the first four labels, the rest of the labels are all put in more.    Create Uitabbarcontroller object Uitabbarcontroller *barvc = [[Uitabbarcontroller alloc] init];    1. Configure multiple view controllers managed by the label View Controller barvc.viewcontrollers = @[firstvc,secondvc,thirdvc,fourvc,fifthvc,sixvc];    3. Modify the rendering color of the tab bar BarVC.tabBar.barTintColor = [Uicolor Whitecolor];        BarVC.tabBar.tintColor = [Uicolor blackcolor];    4. Set the default selected label Barvc.selectedindex = 2;        Set default View Controller Barvc.selectedviewcontroller = THIRDVC;        5. Set the background image for TabBar//barvc.tabbar.backgroundimage = [UIImage imagenamed:@ "320x49"];        6. Set proxy barvc.delegate = self; 7. Designate the view label as the root View Controller for window Self.window.rootViewController = barvc; 
②uitabbarcontroller Controller Common proxy methods are as follows:

asks if the label can be checked-(BOOL) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller Shouldselectviewcontroller: (Uiviewcontroller *) Viewcontroller {return YES;} Trigger when label is selected-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller  didselectviewcontrol        Ler: (Uiviewcontroller *) Viewcontroller {//need to select the second label, then remove the corner mark if (ViewController.tabBarItem.tag = = 101) {    ViewController.tabBarItem.badgeValue = nil;                   }//is about to start customizing multiple view controllers that are managed by the label View Controller, click Edit-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller    Willbegincustomizingviewcontrollers: (Nsarray *) viewcontrollers {NSLog (@ "%s%d", __function__,__line__); NSLog (@ "%@", viewcontrollers); }//triggered when the custom label view Controller is managed by multiple view controllers. Click Done-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller Didendcustomizingviewcontrollers: (Nsarray *) Viewcontrollers changed: (BOOL) changed {NSLog (@ "%s%d", __function__,__    LINE__); NSLog (@ "%@ \ n%d", viewcontrollers,changed);} 
③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 6 sub-controllers, so there are 6 uitabbarbutton,uitabbar structures in the Uitabbar, as shown here:



Uitabbarbutton what content, by the corresponding sub-controller Tabbaritem property to determine the following: Set

    FirstVc.tabBarItem.title = @ "message";    Corner Mark    firstVc.tabBarItem.badgeValue = @ "new";    Set the picture when selected first    Vc.tabBarItem.selectedImage = [UIImage imagenamed:@ "tabbar_contacts"];    Set picture   firstVc.tabBarItem.image = [UIImage imagenamed:@ "Tabbar_mainframe"];

Note: The view is displayed in the same order as it was added, and is different from the navigation controller, and is displayed in front of the view that corresponds to the first controller added.

2.UIToorBar

The tool bar, which is used mainly with the navigation controller, is controlled by the navigation controller and is mainly used to store the auxiliary functions of some systems. In the web switch, comments and so on.
You can add any view on the toolbar. In fact, it is the principle of adding the view you want to add to Uibarbuttonitem inside, and then put the Uibarbuttonitem array one at a time into the toolbar items.

Uibbarbuttonitem has the following initialization methods:
-initwithtitle
-initwithimage
-initwithbarbuttonsystemitem
-initwithcustomview

The implementation results are as follows:


The implementation code is as follows:

    Create Uitoorbar object Uitoolbar *toolbar = [[Uitoolbar alloc] Initwithframe:cgrectmake (0, 64, 320, 49)];  Toolbar.translucent = no;//Configuration Properties, frosted glass effect Toolbar.bartintcolor = [Uicolor greencolor];//background color//Set font style Toolbar.tintcolor   = [Uicolor Purplecolor];   ToolBar style  //toolbar.barstyle = Uibarstyleblackopaque; Set picture [ToolBar setbackgroundimage:[uiimage imagenamed:@ "User_guide_page6"] Fortoolbarposition:uibarpositionbottom   Barmetrics:uibarmetricsdefault];   Added to the view controller's root view [Self.view Addsubview:toolbar];      [ToolBar release]; Uibarbuttonitem Initialization Method 1 (initwithtitle) Uibarbuttonitem *baritems = [[Uibarbuttonitem alloc] initwithtitle:@ "Chick 1" sty    Le:uibarbuttonitemstyleplain target:self Action: @selector (handlebaraction:)];  System button//uibarbuttonitem Initialization Method 2 (initwithbarbuttonsystemitem) Uibarbuttonitem *additems = [[Uibarbuttonitem alloc]    Initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:self Action: @selector (handleaddaction:)]; Add Picture <pre name= "code" class= "OBJC" >//uibarbuttonitem initialization Method 3 (initwithimage) Uibarbuttonitem *imageitems = [[UIBarButt Onitem Alloc] Initwithimage:
[UIImage imagenamed:@ "post_timeline_mood_icon_1"]
Style:uibarbuttonitemstyleplain target:self Action: @selector (handlereplyaction:)];
<pre name= "code" class= "OBJC" >    //uibarbuttonitem Initialization Method 2 (Initwithbarbuttonsystemitem)     Uibarbuttonitem *items = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:                          Uibarbuttonsystemitemflexiblespace target:self Action:nil];    Adjust the spacing between buttonitem    uibarbuttonitem *fiex = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:                            Uibarbuttonsystemitemfixedspace target:self Action:nil];    Fiex.width  =;    Add Uibarbuttonitem to the array     //fiex and items  to the position between the adjustment buttons   nsarray *itemsarr1 = @[items,baritems,fiex,items, Additems,items,imageitems,items];    NSLog (@ "%@", itemsArr1);    Nsarray *itemsarr = @[fiex,baritems,fiex,additems,fiex,imageitems,fiex];    Add    [ToolBar setitems:itemsarr animated:yes];    [Baritems release];    [Itemsarr release];




"Learning the path to iOS: UI series" Uitabbarcontroller, Uitoorbar

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.