首页 > 代码库 > iOS_17_控制器切换_TabBarController_通过storyboard方式
iOS_17_控制器切换_TabBarController_通过storyboard方式
最终效果图:
main.storyboard
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 = http://www.mamicode.com/[NSString stringWithFormat:@"%d",1] ;>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; @endNanaViewController.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 = http://www.mamicode.com/[NSString stringWithFormat:@"%d",2] ;>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; @endSettingViewController.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 = http://www.mamicode.com/[NSString stringWithFormat:@"%d",3] ;>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。