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来建立各个视图控制器间的关系.在需要用到代码进行切换时会 ...
随机推荐
- 关于 typedef & typedef struct & typedef union理解 --写给不长脑子的我
来源: http://zhidao.baidu.com/link?url=qxzkx5gaoCfnHnygYdzaLEWkC45JqNYYUk42eHHjB0yB3ZMgHv6lGjnq3CRfgQw ...
- 提领NULL指针
通常之中导致程序崩溃的最重要的原因是试图取消引用NULL指针.正如在以前的文章中指出,智能指针RefCountPtr和ScopedPtr它提供了一个诊断的执行时间. 但,并不是所有的指针是所有的对象都 ...
- Spring集成XFire开发WebService
Spring是眼下最流行的JavaEE Framework,可是使用Spring的Spring-WS开发WebService却十分繁琐.XFire是一个简化WebService开发的开源项目.通过Sp ...
- 2)JS动态生成HTML元素的爬取
2)JS动态生成HTML元素的爬取 import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.W ...
- hdu 4465 Candy(2012 ACM-ICPC 成都现场赛)
简单概率题,可以直接由剩余n个递推到剩余0个.现在考虑剩余x个概率为(1-p)的candy时,概率为C(2 * n - x, x) * pow(p, n + 1) *pow(1 - p, n - x ...
- dede 首页或列表页调用文章内容页body内容
在使用dede过程,有的朋友会调调出文章的列表的内容出来,怎么调呢?当然是用dede的传参的数据查询语句了,方法如下: {dede:arclist flag=h typeid=2 row=1 titl ...
- Cocos2d-x Layout简单使用
1. Text* alert = Text::create("Layout", "fonts/Marker Felt.ttf", 30 ); alert-> ...
- 我写了一起 Makefile(一)
我写了一起 Makefile 陈皓 概述—— 什么是makefile?也许非常多Winodws的程序猿都不知道这个东西,由于那些Windows的IDE都为你做了这个工作.但我认为要作一个好的和pro ...
- 百度mp3接口
歌曲ID 具体信息接口:http://tingapi.ting.baidu.com/v1/restserver/ting? from=android&version=2.4.0&met ...
- Unity多玩家网络游戏开发教程1章Unity带有网络功能
Unity网络多玩家游戏开发教程第1章Unity自带网络功能 Unity拥有大量的第三方插件.专门提供了对网络功能的支持. 可是.大部分开发人员第一次接触到的还是Unity自带的网络功能.也就是大家常 ...