UITabBarController的创建等基本方法
#import "AppDelegate.h"
@interface AppDelegate () <UITabBarControllerDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// 1.创建window
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// 2.创建UITabBarController对象
UITabBarController *mainTabBar = [[UITabBarController alloc] init];
// 创建控制器对象
UIViewController *firstVC = [[UIViewController alloc] init];
firstVC.view.backgroundColor = [UIColor cyanColor];
// 设置tabBarItem
// 第一种方式:系统样式
firstVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:];
// 第二种方式:自定义样式
UIViewController *secondVC = [[UIViewController alloc] init];
secondVC.view.backgroundColor = [UIColor orangeColor];
// 创建图片
UIImage *secondImg = [UIImage imageNamed:@"carGary@2x"];
UIImage *selectSecondImg = [UIImage imageNamed:@"carRed@2x"];
// 设置图片保留原有样式
secondImg = [secondImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
selectSecondImg = [selectSecondImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
secondVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"two" image:secondImg selectedImage:selectSecondImg];
UIViewController *thirdVC = [[UIViewController alloc] init];
thirdVC.view.backgroundColor = [UIColor redColor];
thirdVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@"findGray@2x"] tag:];
UIViewController *fourthVC = [[UIViewController alloc] init];
fourthVC.view.backgroundColor = [UIColor greenColor];
fourthVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"用户" image:[UIImage imageNamed:@"userGray@2x"] tag:];
UIViewController *fifthVC = [[UIViewController alloc] init];
fifthVC.view.backgroundColor = [UIColor greenColor];
fifthVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:];
UIViewController *sixVC = [[UIViewController alloc] init];
sixVC.view.backgroundColor = [UIColor greenColor];
sixVC.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:];
// 设置控制器数组
mainTabBar.viewControllers = @[firstVC, secondVC, thirdVC, fourthVC, fifthVC, sixVC];
// [mainTabBar addChildViewController:firstVC];
// [mainTabBar addChildViewController:secondVC];
// 3.将UITabBarController对象设置为window的根视图控制器
self.window.rootViewController = mainTabBar;
// 设置进入应用选中第几个
mainTabBar.selectedIndex = ;
#pragma mark - TabBar的属性
// 修改字体图标等的选中颜色
mainTabBar.tabBar.tintColor = [UIColor greenColor];
// 设置tabBar的半透明与否
mainTabBar.tabBar.translucent = NO;
// 设置tabBar的颜色
mainTabBar.tabBar.barTintColor = [UIColor purpleColor];
// 改变tabBar的位置
[secondVC.tabBarItem setTitlePositionAdjustment:UIOffsetMake(, )];
// 设置消息提示
thirdVC.tabBarItem.badgeValue = @"99+";
// 设置代理
mainTabBar.delegate = self;
return YES;
}
#pragma mark - 实现代理方法
// 清除提示消息
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
viewController.tabBarItem.badgeValue = nil;
}
@end
UITabBarController的创建等基本方法的更多相关文章
- 创建控制器的方法、控制器加载view过程、控制器view的生命周期、多控制器组合
在介绍四大对象的那篇博客中,可以基本了解到程序启动的过程: main-->UIApplicationMain-->创建UIApplication的实例和app代理AppDelegate的实 ...
- TabBarController创建及使用方法简介
TabBarController创建及使用方法简介 大致讲解一下TabBarController的创建过程: 首先,我们需要一些视图,如创建UIControllerView类型的view1,view2 ...
- 【iOS开发-30】UITabBarController的几种代理方法以及结合NSUserDefaults还原上次退出时被选中视图控制器和视图控制器的顺序
一.UITabBarController的几种代理方法 在AppDelegate.h中加入一个协议<UITabBarControllerDelegate>.然后再AppDelegate.m ...
- 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间
[源码下载] 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间 作者:webabcd 介绍速战速决 之 PHP 动态地创 ...
- MySQL函数不能创建的解决方法
MySQL函数不能创建,是一个很麻烦的问题,下面就为您提供了一个解决此问题的方法,如果您也遇到过类似的问题,不妨一看. http://database.51cto.com/art/201010/229 ...
- odoo 动态创建字段的方法
动态创建字段并非一个常见的的需求,但某些情况下,我们确实又需要动态地创建字段. Odoo 中创建字段的方法有两种,一种是通过python文件class中进行定义,另一种是在界面上手工创建,odoo通过 ...
- 【转】ArcGIS 创建切片缓存方法工具总结
ArcGIS 创建切片缓存方法工具总结 http://wenku.baidu.com/link?url=Bm8AkmcJBzfiyat9N_Me6vlfSHEDCC_D1qBk5IB4X4CIDeKI ...
- C#两种创建快捷方式的方法
C#两种创建快捷方式的方法http://www.cnblogs.com/linmilove/archive/2009/06/10/1500989.html
- asp.net创建XML文件方法
方法一:按照XML的结构一步一步的构建XML文档. 通过.Net FrameWork SDK中的命名空间"System.Xml"中封装的各种类来实现的 方法一:按照XML的结 ...
随机推荐
- 将XmlDocument转换成XDocument
XmlDocument xml=new XmlDocument(); xml.LoadXml(strXmlText); XmlReader xr=new XmlNodeReader(xml); XDo ...
- 你需要知道的Sass插值
你也许会不时地写写 Sass 玩玩,你也会很享受它带给你各种便利.但还有一件事,你并不一定完全了解:插值 (interpolation) - 将一个占位符,替换成一个值.好了,你们都很幸运,因为今天我 ...
- shell的重定向
>file 将file文件重定向为输出源,新建模式,可以将正确的结果输出到file文件 >>file 将file文件重定向为输出源,追加模式 <file 将file文件重定 ...
- 解决debian中脚本无法使用source的问题
#!/bin/sh source scripts/common.sh 现象: shell脚本中source aaa.sh时提示 source: not found 原因: ls -l `which s ...
- [转载]在线文档预览方案-Office Web Apps
最近在做项目时,要在手机端实现在线文档预览的功能.于是百度了一下实现方案,大致是将文档转换成pdf,然后在通过插件实现预览.这些方案没有具体实现代码,也没有在线预览的地址,再加上项目时间紧迫.只能考虑 ...
- EPANET头文件解读系列8——FUNCS.H
/*************************************************************************** ...
- ASP.NET在不同情况下实现单点登陆(SSO)的方法
第一种:同主域但不同子域之间实现单点登陆 Form验证其实是基于身份cookie的验证.客户登陆后,生成一个包含用户身份信息(包含一个ticket)的cookie,这个cookie的名字就是在web. ...
- ExtendHelper
public static class ExtendHelper { /// <summary> /// 检查当前字符串是否符合某种格式 /// </summary> /// ...
- BZOJ1008 /乘法原理+快速幂 解题报告
1008: [HNOI2008]越狱 Description 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生 ...
- 如何理解css中的float
最近一段时间一直在为一个即将上线的新站进行一些前端开发.自然,对CSS的使用是必不可少的了.我们在CSS 中很多时候会用到浮动来布局.常见的有 float:left 或者 float:right .简 ...