#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的创建等基本方法的更多相关文章

  1. 创建控制器的方法、控制器加载view过程、控制器view的生命周期、多控制器组合

    在介绍四大对象的那篇博客中,可以基本了解到程序启动的过程: main-->UIApplicationMain-->创建UIApplication的实例和app代理AppDelegate的实 ...

  2. TabBarController创建及使用方法简介

    TabBarController创建及使用方法简介 大致讲解一下TabBarController的创建过程: 首先,我们需要一些视图,如创建UIControllerView类型的view1,view2 ...

  3. 【iOS开发-30】UITabBarController的几种代理方法以及结合NSUserDefaults还原上次退出时被选中视图控制器和视图控制器的顺序

    一.UITabBarController的几种代理方法 在AppDelegate.h中加入一个协议<UITabBarControllerDelegate>.然后再AppDelegate.m ...

  4. 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间

    [源码下载] 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间 作者:webabcd 介绍速战速决 之 PHP 动态地创 ...

  5. MySQL函数不能创建的解决方法

    MySQL函数不能创建,是一个很麻烦的问题,下面就为您提供了一个解决此问题的方法,如果您也遇到过类似的问题,不妨一看. http://database.51cto.com/art/201010/229 ...

  6. odoo 动态创建字段的方法

    动态创建字段并非一个常见的的需求,但某些情况下,我们确实又需要动态地创建字段. Odoo 中创建字段的方法有两种,一种是通过python文件class中进行定义,另一种是在界面上手工创建,odoo通过 ...

  7. 【转】ArcGIS 创建切片缓存方法工具总结

    ArcGIS 创建切片缓存方法工具总结 http://wenku.baidu.com/link?url=Bm8AkmcJBzfiyat9N_Me6vlfSHEDCC_D1qBk5IB4X4CIDeKI ...

  8. C#两种创建快捷方式的方法

    C#两种创建快捷方式的方法http://www.cnblogs.com/linmilove/archive/2009/06/10/1500989.html

  9. asp.net创建XML文件方法

    方法一:按照XML的结构一步一步的构建XML文档.    通过.Net FrameWork SDK中的命名空间"System.Xml"中封装的各种类来实现的 方法一:按照XML的结 ...

随机推荐

  1. C#基础总结之六 DataTable (临时表/数据源) 和Datatable 名片练习

    #region DataTable (临时表/数据源) 存储数据 DataTable dataTable = new DataTable(); dataTable.Columns.Add(" ...

  2. 使用unetbootin制作Debian安装U盘

    有时需要在没有光驱的裸机上安装系统,这时我们可以使用unetbootin制作一个系统安装U盘. 1.在网上下载好vmlinuz,initrd.gz,boot.img.gz. 2.然后使用unetboo ...

  3. Machine Learning : Pre-processing features

    from:http://analyticsbot.ml/2016/10/machine-learning-pre-processing-features/ Machine Learning : Pre ...

  4. Gamma Gamma~!!!

    左图是没有进行gamma矫正的,右图是进行了gamma矫正的.以前一直以为是Tone Map的公式计算有问题,后来看PBR的paper时候,终于明白了gamma的重要性,一改,果然发现颜色不想以前那么 ...

  5. STM32L051 PVD的调试

    我的PVD的驱动以及例程位于STM32L0xx_Drivers这个库当中,在使用前最好先阅读readme.md文件 PVD 是一种检测MCU供电情况的技术.当供电电压高于或者低于一定阈值的时候,可以在 ...

  6. (翻译)为你的MVC应用程序创建自定义视图引擎

    Creating your own MVC View Engine For MVC Application 原文链接:http://www.codeproject.com/Articles/29429 ...

  7. UWP开发入门(十四)—— UserControl中Adaptive UI的小技巧

    本篇我们通过绘制一个非常简单的UserControl控件,来分享一下对Adaptive UI的理解及一些图形绘制的技巧. 现在流行的APP都少不了精致的用户头像,首先假设我们需要绘制如下的图形作为默认 ...

  8. Weblogic魔法堂:AdminServer.lok被锁导致启动、关闭域失败

    一.判断AdminServer.lok被其进程锁死 >weblogic.management.ManagementException: Unable to obtain lock on **** ...

  9. 自定义UICollectionViewController之后 如何设置UICollectionView的布局方式

    我们很多时候使用UICollectionView 可能都是直接创建 UICollectionView   通过初始化的时候  传入一个布局对象的方式来使用UICollectionView 比如我们之前 ...

  10. [Architect] Abp 框架原理解析(2) EventBus

    本节目录 原理介绍 Abp源码分析 代码实现 原理介绍 事件总线大致原理: (1)       在事件总线内部维护着一个事件与事件处理程序相映射的字典. (2)       利用反射,事件总线会将实现 ...