• storybored 线拖tabbarvc app去保存对象


    最终效果图:

    方式,切换,ios_17_,tabbarcontroller_,storyboard0

    main.storyboard

    方式,切换,ios_17_,tabbarcontroller_,storyboard1

    BeyondViewController.m中有一句关键代码,设置tabbarItem图片的样式(30*30)

    //
    //  BeyondViewController.m
    //  17_控制器切换2_tabbarController
    //
    //  Created by beyond on 14-7-31.
    //  Copyright (c) 2014年 com.beyond. 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里面的tabbarItem中的图片需要特殊API处理之后,才能正常显示
        UIImage *img = [UIImage imageNamed:@"home"];
        UIImage *img_selected = [UIImage imageNamed:@"home_s"];
        // 设置图片 渲染 模式
        img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        // 设置图片 渲染 模式
        img_selected = [img_selected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        // 构造方法生成 UITabBarItem
        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"" image:img selectedImage:img_selected];
        
        // 设置当前控制器的 tabBarItem属性
        self.tabBarItem = item;
        self.tabBarItem.title = @"首页";
        self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",1] ;
        
        
        // 默认情况下,app运行之后,只执行第一个控制器的view did load方法,因此,要得到UITabBarController容器中所有的控制器,调用其自定义的一个方法,设置它们自己的tabbaritem样式
        
        // 先得到父容器UITabBarController,有了它,就有了所有的控制器实例的引用
        UITabBarController *parentCtrl = self.parentViewController;
        // 得到容器UITabBarController中所有的子控制器
        NSArray *children = [parentCtrl childViewControllers];
        // 调用对应的子控制器的 自定义方法,设置它们自己的tabbaritem样式
        NanaViewController *nanaVC = (NanaViewController *)[children objectAtIndex:1];
        [nanaVC setTabBarItemDIY];
        
        // 调用对应的子控制器的 自定义方法,设置它们自己的tabbaritem样式
        SettingViewController *setVC = (SettingViewController *)[children objectAtIndex:2];
        [setVC setTabBarItemDIY];
        
    }
    
    
    @end
    



    NanaViewController.h

    //
    //  NanaViewController.h
    //  17_控制器切换2_tabbarController
    //
    //  Created by beyond on 14-7-31.
    //  Copyright (c) 2014年 com.beyond. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface NanaViewController : UIViewController
    
    
    // 自定义方法,设置自己的tabbaritem样式
    - (void) setTabBarItemDIY;
    @end
    



    NanaViewController.m

    //
    //  NanaViewController.m
    //  17_控制器切换2_tabbarController
    //
    //  Created by beyond on 14-7-31.
    //  Copyright (c) 2014年 com.beyond. All rights reserved.
    //
    
    #import "NanaViewController.h"
    
    @interface NanaViewController ()
    
    @end
    
    @implementation NanaViewController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        NSLog(@"view did loaded  2");
        
        
    }
    // 自定义方法,设置自己的tabbaritem样式
    - (void) setTabBarItemDIY
    {
        // UITabbarController里面的tabbarItem中的图片需要特殊API处理之后,才能正常显示
        UIImage *img = [UIImage imageNamed:@"nana"];
        UIImage *img_selected = [UIImage imageNamed:@"nana_s"];
        // 设置图片 渲染 模式
        img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        // 设置图片 渲染 模式
        img_selected = [img_selected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        // 构造方法生成 UITabBarItem
        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"" image:img selectedImage:img_selected];
        
        // 设置当前控制器的 tabBarItem属性
        self.tabBarItem = item;
        self.tabBarItem.title = @"娜娜";
        self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",2] ;
    }
    
    @end
    



    SettingViewController.h

    //
    //  SettingViewController.h
    //  17_控制器切换2_tabbarController
    //
    //  Created by beyond on 14-7-31.
    //  Copyright (c) 2014年 com.beyond. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface SettingViewController : UIViewController
    
    // 自定义方法,设置自己的tabbaritem样式
    - (void) setTabBarItemDIY;
    @end
    



    SettingViewController.m

    //
    //  SettingViewController.m
    //  17_控制器切换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 initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        NSLog(@"view did loaded  3");
        
        
    }
    
    // 自定义方法,设置自己的tabbaritem样式
    - (void) setTabBarItemDIY
    {
        // UITabbarController里面的tabbarItem中的图片需要特殊API处理之后,才能正常显示
        UIImage *img = [UIImage imageNamed:@"setting"];
        UIImage *img_selected = [UIImage imageNamed:@"setting_s"];
        // 设置图片 渲染 模式
        img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        // 设置图片 渲染 模式
        img_selected = [img_selected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        // 构造方法生成 UITabBarItem
        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"" image:img selectedImage:img_selected];
        
        // 设置当前控制器的 tabBarItem属性
        self.tabBarItem = item;
        self.tabBarItem.title = @"我的";
        self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",3] ;
    }
    @end
    



  • 相关阅读:
    通联支付相关注意事项
    账号配置vue版本的扫码下单以及对店铺进行装修的步骤
    银盒子扫码下单在线订单开启商品售卖时段使用说明
    ERP承接新后台优惠规则问题
    简易付安装后无法使用
    ASP.NET没有魔法——ASP.NET Identity 的“多重”身份验证代码篇
    ASP.NET没有魔法——ASP.NET Identity 的“多重”身份验证
    ASP.NET没有魔法——ASP.NET MVC 过滤器(Filter)
    ASP.NET没有魔法——ASP.NET Identity与授权
    ASP.NET没有魔法——ASP.NET Identity的加密与解密
  • 原文地址:https://www.cnblogs.com/dbaiyunyun/p/5046245.html
Copyright © 2020-2023  润新知