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 = [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
版权声明:本文博客原创文章。博客,未经同意,不得转载。
iOS_17_控制开关_TabBarController_由storyboard道路的更多相关文章
- 免费道路 bzoj 3624
免费道路(1s 128MB)roads [输入样例] 5 7 21 3 04 5 13 2 05 3 14 3 01 2 14 2 1 [输出样例] 3 2 04 3 05 3 11 2 1 题解: ...
- LaunchScreen.storyboard启动图遇到的坑
Xcode有时候在LaunchScreen.storyBoard中修改了启动图片之后,运行却没有效果,直接白屏,而往storyboard中拖插件是可以显示的,设置成Assets.xcassets中的其 ...
- iOS系列 基础篇 02 StoryBoard 故事板文件
iOS基础 02 StoryBoard 故事板文件 目录: 1. 故事板的导航特点 2. 故事板中的Scene和Segue 3. 本文最后 在上篇HelloWorld工程中有一个Main.storyb ...
- Xcode6新特性(1)-删除Main.storyboard
当新建完一个空项目的时候,Xcode会自动创建一个Main.storyboard的空文件,如果不需要,可以将其删除.但是如果删除,再次运行程序,程序会报错,提示找不到Main.storyboard文件 ...
- Storyboard & XIB 自己的理解
//1.storyboard //(1) //此处bundle:nil 等价于 [NSBundle mainBundle] // SecondViewController *secondVc = ...
- 控制Storyboard播放zz
<Grid Width="300" Height="460"> <Grid.RowDefinitions> <RowDefinit ...
- 代码中使用StoryBoard和DoubleAnimation的方法
TranslateTransformを対象に.DoubleAnimation型のアニメーションを使用して.TranslateTransform.Xプロパティを ”-1 * Imageコントロールの幅” ...
- iOS开发之使用Storyboard预览UI在不同屏幕上的运行效果
在公司做项目一直使用Storyboard,虽然有时会遇到团队合作的Storyboard冲突问题,但是对于Storyboard开发效率之高还是比较划算的.在之前的博客中也提到过,团队合作使用Storyb ...
- IOS开发之获取Storyboard创建的ViewController
前面的两篇博客都是学习有关屏幕适配也就是相对布局的东西,这篇博客中将会学习视图间的切换.视图间的切换我们可以用代码完成或者用storyboard来建立各个视图控制器间的关系.在需要用到代码进行切换时会 ...
随机推荐
- 【C#遗补】之Char.IsDigit和Char.IsNumber的区别
原文:[C#遗补]之Char.IsDigit和Char.IsNumber的区别 Char中IsDigit和IsNumber的两个方法都是用来判断字符是否是数字的,那他们有什么区别 IsDigit ...
- 使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(二)——自定义安装
原文:使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(二)--自定义安装 自定义产品卸载方式 继续从上一次的基础上前进,现在我们已经知道了最简单的bootstr ...
- 解决vmware“二进制转换和长模式与此平台兼容.....”问题
问题描述: 启动vmware显现:1.二进制转换和长模式与此平台兼容....字等.: 2.vmware启动一会,系统直接重新启动,这个现象出如今惠普电脑上 问题原因: 出现这种原因一般都是因为系统Vi ...
- asp.net操作word的表格
近日开发中用户要求实现导出数据为Word,本来想使用html保存为word的实现,但因用户要求样式很高,使用html不好控制,并且导出中包括图片,使用页面导出时图片还是一个路径,不能把图片包括在wor ...
- Cannot instantiate the type List<Integer>
在使用java.util.List; 的时候,把语句写成了: List<Integer> arr = new List<Integer>(); 导致错误: Cannot ins ...
- 【cocos2d-js官方文档】十、log
api修改情况.左边为新增,右边为原来的. cc.log 不变 cc.warn 新增 cc.error 新增 cc.assert <-- cc.Assert 此次改造有下面几点原因: 加入原来没 ...
- android学习---SeekBar和RatingBar
SeekBar 拖动条:拖动条和滚动栏类似,当是拖动条能够拖动滑块改变进度 RatingBar 星级评分条:星级评分条与拖动条相似 SeekBar特有的xml属性 android:thumb 指 ...
- wscript:329: error: Could not autodetect OpenSSL support. Make sure OpenSSL development packages are
安装node错: wscript:329: error: Could not autodetect OpenSSL support. Make sure OpenSSL development pac ...
- Automatically generate serial number in abap
流水号的产生: 在ABAP开发中,很多地方都需要按照自己的规则生成流水号,把这些流水号保存进透明表,作为唯一标示. 一. 系统中设定流水号 使用T-Code SNRO来创建一个流水号标识对象. 输 ...
- 你怎么知道你的网站K
最近有朋友问我关于网站K问题,你怎么知道被提及哪些网站K方面.总结了六个方法后,,至于有没有其他办法.欢迎和我交流讨论. 检测方法是网站的搜索引擎惩罚: 首先要明白的是.搜索引擎不惩罚easy侦查 ...