UI Grooming-----part9--Label Controller (Tabbarcontroller)

Source: Internet
Author: User

1.UITabBarController: Similar to Uinavigationcontroller, you can easily manage multiple controllers and easily convert between spaces.

Use of 2.UITabBarController:

(1) Steps to use:

<1> Initialize Uitabbarcontroller

<2> set UIWindow Rootviewcontroller to Uitabbarcontroller

<3> creating the appropriate sub-controller (Viewcontroller)

<4> handle controller added to Uitabbarcontroller

(2) Code Demo:

3. Important NOTE:

(1) Uitabbar: The View controller contains a Tabbar control (i.e., the tool bar below), if Uitabbar has n controllers, Then Uitabbar will have n Uitabbarbutton as child controls (the default used Uitabbarbutton in Uitabbar is evenly divided, and the Uitabbar height is 49). If the number of controls is more than 5, it will produce a "more" at the right end of the Tabbar, showing the first 4, and then in "more", the position can be exchanged.

(2) What content is displayed inside the Uitabbarbutton:uitabbarbutton, determined by the Tabbaritem attribute in the corresponding sub-controller

(3) Two ways to add a sub-controller to the Tabbarcontroller:

if Tabbarc.selectedindex = 1; Then set the second view as the default tab

4. If you are using a system-given style:

<1> by invoking at Uitabbaritem initialization-(instancetype) Initwithtabbarsystemitem: (Uitabbarsystemitem) Systemitemtag: ( Nsinteger) tag; method to set the label item.

<2> System label Items list:

Typedefns_enum (Nsinteger, Uitabbarsystemitem) {

Uitabbarsystemitemmore, this tab appears when the number of pictures in the tab bar is more than 5, and clicking on this tab will display an icon that is not displayed.

Uitabbarsystemitemfavorites, personal collection content

uitabbarsystemitemfeatured, program recommended content

uitabbarsystemitemtoprated, high-rated content

uitabbarsystemitemrecents, recently accessed content

Uitabbarsystemitemcontacts, Address Book interface

Uitabbarsystemitemhistory, historical content

Uitabbarsystemitembookmarks, bookmark content

Uitabbarsystemitemsearch, search interface

uitabbarsystemitemdownloads, download/download complete content

Uitabbarsystemitemmostrecent, what's new

Uitabbarsystemitemmostviewed, the most popular content

};

5. Tab Bar Properties

6. Custom Tab Bar

1.        When the view is about to be displayed, the Tabbar native button is removed-(void) Viewwillappear: (BOOL) animated{[Super viewwillappear:animated];  For (UIView *view in self.tabBar.subviews) {if ([View iskindofclass:nsclassfromstring (@ "Uitabbarbutton")])        {[View Removefromsuperview];        }}}//2. Create a custom tabbar-(void) viewdidload {[Super viewdidload];    _newtabbar.frame = CGRectMake (0, 0, [UIScreen mainscreen].bounds.size.width, 49);    [Self.tabbar Addsubview:_newtabbar];        }//3. Override the following method to add a custom control-(void) Setviewcontrollers: (nsarray<__kindof uiviewcontroller *> *) viewcontrollers{        The goal is to tell the system the number of controllers that need to be created [super setviewcontrollers:viewcontrollers];        Custom controller [self creatnewcontrollerwithselectimagename:selectimagename]; }-(void) Creatnewcontrollerwithselectimagename: (NSString *) selectimagename{//width of the control created cgfloat controlwidth = [    UIScreen Mainscreen].bounds.size.width/self.viewcontrollers.count; Initializes the back of the selected controlView _selectimage = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0,controlwidth, 49)];        _selectimage.image = [UIImage imagenamed:selectimagename];        [_newtabbar Addsubview:_selectimage];        First understand the number of controllers generated by the For loop for (int i = 0; i < self.viewControllers.count; i + +) {//Custom controls                Uicontrol *newcontrol = [[Uicontrol alloc] Initwithframe:cgrectmake (i * controlwidth, 0, Controlwidth, 45)];                Add custom Tabbarbutton to Custom Tabbar [_newtabbar Addsubview:newcontrol]; Add click Effect [NewControl addtarget:self action: @selector (controlaction:) forcontrolevents:uicontroleventtouchupinside]        ;                By setting the tag convenient transfer value Newcontrol.tag = + i;                Get the current controller Uiviewcontroller *VIEWC = [Self.viewcontrollers objectatindex:i];        Get the picture and information before uiimageview *imageview = [[Uiimageview alloc] init];                Imageview.image = ViewC.tabBarItem.image; UILabel *label =[[UILabel alloc] init];                    Label.text = ViewC.tabBarItem.title;         }}//-(void) Controlaction: (Uicontrol *) control{self.selectedindex = control.tag-1000;//switch by the obtained tag value Viewcontroller    Implementation of the motion animation effect [UIView animatewithduration:.4 animations:^{_selectimage.center = control.center; }];}  /* Details are important (1) with Tabbar's SelectedIndex attribute, you can associate a button you create with Viewcontroller (2) to cancel the system's highlighting: You can define a button, overwrite the Sethighlied method inside, and do nothing. (3) About a few buttons only select one method: Set a property, record the last selected button, click the current button, set the previous button is not selected, and the current button is set to select, and finally assign the current button to the previous button */

UI Grooming-----part9--Label Controller (Tabbarcontroller)

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.