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来建立各个视图控制器间的关系.在需要用到代码进行切换时会 ...
随机推荐
- uva :10123 - No Tipping(dfs + 几何力矩 )
option=com_onlinejudge&Itemid=8&page=show_problem&category=109&problem=1064&mosm ...
- poj1651(区间dp)
题目连接:http://poj.org/problem?id=1651 题意:给出一组N个数,每次从中抽出一个数(第一和最后一个不能抽),该次的得分即为抽出的数与相邻两个数的乘积.直到只剩下首尾两个数 ...
- POJ 2676/2918 数独(dfs)
思路:记录每行每列每一个宫已经出现的数字就可以.数据比較弱 另外POJ 3074 3076 必须用剪枝策略.但实现较麻烦,还是以后学了DLX再来做吧 //Accepted 160K 0MS #incl ...
- OpenStack安装与配置2
第二部分 OpenStack安装与配置 一.引言 本章内容讲解如何在3台物理机上搭建最小化云平台,这3台机器分为称为Server1.Server2和Client1,之后的各章也是如此.Server ...
- PHPDocumentor代码注释规范说明
PHPDocumentor是一个的用PHP写的道具,对于有规则注释的php程序,它能够快速生成具有相互参照,索引等功能的API文档. 标记 用途 描述 @abstract 抽象类的变量和方法 ...
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第15章节--开发SP2013工作流应用程序 总结
BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第15章节--开发SP2013工作流应用程序 总结 在SP2013中,工作流已经从SP Server中脱离 ...
- PHP类中的七种语法说明
类中的七种语法说明 -属性 -静态属性 -方法 -静态方法 -类常量 -构造函数 -析构函数 <?php class Student { // 类里的属性.方法和函数的訪问权限有 (函数和方法是 ...
- swift学习一:介绍,开发文档下载
在今天wwdc2014公布会上.苹果今天公布了全新的编程语言Swift以及新版Xcode.对于开发人员来说,Swift包括了非常多开发人员喜欢的功能,能够与Objective-C和C语言共同工作.Sw ...
- C++经典面试题(二)
近期看一些面试题,认为假设自己被问到了,并不能非常利落的回答出来. 一是从来没有这个意识,二是没有认真的梳理下. 以下对这些题做出分析,哈!个人能力有限,当中难免有疏漏,欢迎大家补充咯. 11.引用与 ...
- FREESWITCH SEESION
SESSION SESSION为FS的核心概念之一,所以需要拿出来专门的分析下. 从以下几个方面进行分析,结构类型,资源的管理,对于呼叫的意义,规格. 1.结构类型 每一次呼叫会申请一个session ...