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的结 ...
随机推荐
- win7左ctrl和左alt键互换
主要参考这篇文章: http://xyztony1985.blog.163.com/blog/static/3611782011752420104/ 感谢原博主 Windows Registry Ed ...
- Vim 插件之 NERDTree
设置快键键 编辑 .vimrc 添加以下内容后,可以使用 ctrl + n 来开关 NERDTree 插件. map <silent> <C-n> :NERDTreeToggl ...
- NoSuchMethodError: antlr.collections.AST.getLine()I
错误完整表述: Filter execution threw an exception] with root cause java.lang.NoSuchMethodError: antlr.coll ...
- [Bootstrap]7天深入Bootstrap(4)CSS组件
Bootstrap框架的三大核心之二:组件. 组件也是最核心的地方,因为绝大部分的网页都必须利用组件才能构建出绚丽的页面. 组件包括:Icon图标(Glyphicon). 下拉菜单(Dropdown) ...
- JavaScript--DOM修改元素的属性
一旦你获得了要修改的元素,可以有2种方式,来读取和修改它的属性:一种老的方式(它被更多的用户代理所支持)和一种新的DOM方法的方式.老的和新的用户代理都允许你以对象属性的方式获取和设置元素的属性. 先 ...
- 重构第10天:提取方法(Extract Method)
理解:经常写的代码中,有一些计算逻辑比较复杂的方法,写下来一个很长很长的方法,我们可以把这个方法,根据功能,分解成单独的几个小方法.这样做不仅能够增加代码的可维护性,而且增加了易读性. 详解: 重构前 ...
- [CLR via C#]9. 参数
一.可选参数和命名参数 在设计一个方法的参数时,可为部分或全部参数分配默认值.然后,调用这些方法的代码时可以选择不指定部分实参,接受默认值.此外,调用方法时,还可以通过指定参数名称的方式为其传递实参. ...
- [转]基于 Quercus 的手游项目终于上线了
原文:http://blog.andsky.com/quercus-php-ngame/ 经过半年的开发,我们第一款手游戏终于开发完毕,架构使用了 netty + Quercus 实现用 php 通过 ...
- 启动Eclipse 弹出"Failed to load the JNI shared library jvm.dll"错误
启动Eclipse 弹出"Failed to load the JNI shared library jvm.dll"错误,如下 原因:eclipse的版本与jre或者jdk版本不 ...
- 回文串---Best Reward
HDU 3613 Description After an uphill battle, General Li won a great victory. Now the head of state ...