IOS_17_ Controller switch _tabbarcontroller_ by storyboard mode

Source: Internet
Author: User
Tags uikit

Eventually:



Main.storyboard



There is a key code in BEYONDVIEWCONTROLLER.M that sets the style of the Tabbaritem picture (30*30)

beyondviewcontroller.m//17_ Controller Switch 2_tabbarcontroller////Created by beyond on 14-7-31.//Copyright (c) 2014 COM.B Eyond. All rights reserved.//#import "BeyondViewController.h" #import "NanaViewController.h" #import " SettingViewController.h "@interface Beyondviewcontroller () @end @implementation beyondviewcontroller-(void)        viewdidload{[Super Viewdidload];        NSLog (@ "view did Loaded");    Uitabbarcontroller inside the Tabbaritem in the picture needs Special API processing, in order to display UIImage *img = [UIImage imagenamed:@ "Home"];    UIImage *img_selected = [UIImage imagenamed:@ "home_s"];    Set Picture Rendering mode IMG = [img imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];        Set Picture rendering Mode img_selected = [img_selected imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Construction method generates Uitabbaritem uitabbaritem *item = [[Uitabbaritem alloc] initwithtitle:@ "" Image:img selectedimage:img_selecte        D];    Sets the Tabbaritem property of the current controller Self.tabbaritem = Item;    Self.tabBarItem.title = @ "Home"; SElf.tabBarItem.badgeValue = [NSString stringwithformat:@ "%d", 1]; By default, after the app runs, only the view did load method for the first controller is executed, so to get all the controllers in the Uitabbarcontroller container, call their own custom method, set their own tabbaritem style//Get first    The parent container uitabbarcontroller, with it, has all the references to the controller instance Uitabbarcontroller *parentctrl = Self.parentviewcontroller;    Get all the sub-controllers in the container uitabbarcontroller nsarray *children = [Parentctrl childviewcontrollers];     Call the corresponding child controller's custom method, set their own tabbaritem style nanaviewcontroller *NANAVC = (Nanaviewcontroller *) [children objectatindex:1];        [NANAVC Settabbaritemdiy]; Call the corresponding child controller's custom method, set their own tabbaritem style settingviewcontroller *SETVC = (Settingviewcontroller *) [Children Objectatinde    X:2];    [SETVC Settabbaritemdiy]; } @end


NanaViewController.h

  nanaviewcontroller.h//  17_ Controller switch 2_tabbarcontroller////  Created by beyond on 14-7-31.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface nanaviewcontroller:uiviewcontroller//custom method, Set your own tabbaritem style-(void) Settabbaritemdiy; @end


Nanaviewcontroller.m



nanaviewcontroller.m//17_ Controller Switch 2_tabbarcontroller////Created by beyond on 14-7-31.//Copyright (c) 2014 Com.bey Ond. All rights reserved.//#import "NanaViewController.h" @interface Nanaviewcontroller () @end @implementation nanaviewcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [Super init    Withnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;}    -(void) viewdidload{[Super Viewdidload];    Do any additional setup after loading the view.        NSLog (@ "View did loaded 2"); }//custom method, set your own tabbaritem style-(void) settabbaritemdiy{//Uitabbarcontroller inside the tabbaritem of the picture needs Special API processing, before the normal display Uiima    GE *img = [UIImage imagenamed:@ "Nana"];    UIImage *img_selected = [UIImage imagenamed:@ "nana_s"];    Set Picture Rendering mode IMG = [img imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Set Picture rendering Mode img_selected = [img_selected Imagewithrenderingmode:uiimagerEnderingmodealwaysoriginal]; Construction method generates Uitabbaritem uitabbaritem *item = [[Uitabbaritem alloc] initwithtitle:@ "" Image:img selectedimage:img_selecte        D];    Sets the Tabbaritem property of the current controller Self.tabbaritem = Item;    Self.tabBarItem.title = @ "Nana"; Self.tabBarItem.badgeValue = [NSString stringwithformat:@ "%d", 2];} @end


SettingViewController.h

  settingviewcontroller.h//  17_ Controller switch 2_tabbarcontroller////  Created by beyond on 14-7-31.//  Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface settingviewcontroller:uiviewcontroller//custom method, Set your own tabbaritem style-(void) Settabbaritemdiy; @end


Settingviewcontroller.m

settingviewcontroller.m//17_ Controller Switch 2_tabbarcontroller////Created by beyond on 14-7-31.//Copyright (c) 2014 COM. Beyond. All rights reserved.//#import "SettingViewController.h" @interface Settingviewcontroller () @end @implementation settingviewcontroller-(ID) initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{self = [Super I    Nitwithnibname:nibnameornil Bundle:nibbundleornil]; if (self) {//Custom initialization} return to self;}    -(void) viewdidload{[Super Viewdidload];    Do any additional setup after loading the view.        NSLog (@ "View did loaded 3"); }//custom method, set your own tabbaritem style-(void) settabbaritemdiy{//Uitabbarcontroller inside the tabbaritem of the picture needs Special API processing, before the normal display Uiima    GE *img = [UIImage imagenamed:@ "setting"];    UIImage *img_selected = [UIImage imagenamed:@ "setting_s"];    Set Picture Rendering mode IMG = [img imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Set Picture rendering Mode img_selected = [img_selected imagewithrendEringmode:uiimagerenderingmodealwaysoriginal]; Construction method generates Uitabbaritem uitabbaritem *item = [[Uitabbaritem alloc] initwithtitle:@ "" Image:img selectedimage:img_selecte        D];    Sets the Tabbaritem property of the current controller Self.tabbaritem = Item;    Self.tabBarItem.title = @ "my"; Self.tabBarItem.badgeValue = [NSString stringwithformat:@ "%d", 3];} @end




















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.