利用代码添加UITabBarController

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  2.  
  3. ViewController *vc1 = [[ViewController alloc] init];
  4.  
  5. UserGuideViewController *vc2 = [[UserGuideViewController alloc] init];
  6.  
  7. UITabBarController *tabBarController = [[UITabBarController alloc] init];
  8. tabBarController.viewControllers = [[NSArray alloc] initWithObjects:vc1, vc2, nil];
  9.  
  10. for(int i=; i<tabBarController.tabBar.items.count; i++) {
  11. UITabBarItem *item = [tabBarController.tabBar.items objectAtIndex:i];
  12.  
  13. item.title = [NSString stringWithFormat:@"子栏目%d",i];
  14.  
  15. NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor],UITextAttributeTextColor, nil];
  16. [item setTitleTextAttributes:dict forState:UIControlStateNormal];
  17.  
  18. NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],
  19. UITextAttributeTextColor,nil];
  20. [item setTitleTextAttributes:dict2 forState:UIControlStateSelected];
  21. }
  22.  
  23. self.window.rootViewController = tabBarController;
  24. [self.window makeKeyAndVisible];
  25.  
  26. return YES;
  27. }

改变TabBar的背景色

方法一:

  1. UIView *bgView = [[UIView alloc] initWithFrame:self.tabBar.bounds];
  2. bgView.backgroundColor = [UIColor redColor];
  3. [self.tabBar insertSubview:bgView atIndex:];

方法二:

  1. CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
  2. UIGraphicsBeginImageContext(rect.size);
  3. CGContextRef context = UIGraphicsGetCurrentContext();
  4. CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
  5. CGContextFillRect(context, rect);
  6. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  7. UIGraphicsEndImageContext();
  8.  
  9. self.tabBar.backgroundImage = image;

改变TabBarItem的(选择/未选择)背景图片

方法一,改变全局:

  1. UIImage *bgImage = [UIImage imageNamed:@"Image1"];
  2. [[UITabBar appearance] setBackgroundImage:[bgImage resizableImageWithCapInsets:UIEdgeInsetsZero]];
  3. [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"Image2"]];

方法二,改变特定:

  1. [self.tabBar setBackgroundImage:[UIImage imageNamed:@"GuideImage1"]];
  2. [self.tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"GuideImage2"]];

改变TabBarItem的选择与未选择图标

  1. - (void)viewDidLoad {
  2. [super viewDidLoad];
  3.  
  4. UIImage *carIcon = [UIImage imageNamed:@"CarIcon"];
  5. UIImage *grayCarIcon = [UIImage imageNamed:@"GrayCarIcon"];
  6.  
  7. ViewController *vc1 = [[ViewController alloc] init];
  8. UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"栏目A" image:carIcon tag:];
  9. item1.selectedImage = grayCarIcon;
  10. vc1.tabBarItem = item1;
  11.  
  12. UserGuideViewController *vc2 = [[UserGuideViewController alloc] init];
  13. UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"栏目B" image:carIcon tag:];
  14. item2.selectedImage = grayCarIcon;
  15. vc2.tabBarItem = item2;
  16.  
  17. self.viewControllers = [[NSArray alloc] initWithObjects:vc1, vc2, nil];
  18.  
  19. [self setSelectedViewController:vc2];
  20. }

改变TabBarItem的文本颜色

  1. UITabBarItem *item = self.tabBar.items[];
  2.  
  3. NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor],UITextAttributeTextColor, nil];
  4. [item setTitleTextAttributes:dict forState:UIControlStateNormal];
  5.  
  6. NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],
  7. UITextAttributeTextColor,nil];
  8. [item setTitleTextAttributes:dict2 forState:UIControlStateSelected];

UITabBarController的一些基础设置的更多相关文章

  1. linux基础-第十四单元 Linux网络原理及基础设置

    第十四单元 Linux网络原理及基础设置 三种网卡模式图 使用ifconfig命令来维护网络 ifconfig命令的功能 ifconfig命令的用法举例 使用ifup和ifdown命令启动和停止网卡 ...

  2. hibernate----hibernate的基础设置

    本次学习的内容是hibernate的基础设置 具体内容为: 一.准备工作 1.新建java工程 2.自动引入相关库(自动生成SessionFactory) 3.将数据库驱动拿进来 4.添加hibern ...

  3. Linux网络服务01——Linux网络基础设置

    Linux网络服务01--Linux网络基础设置 一.查看及测试网络 1.使用ifconfig命令查看网络接口 (1)查看活动的网络接口 ifconfig命令 [root@crushlinux ~]# ...

  4. iptables 生产环境下基础设置

    iptables 生产环境下基础设置 生成环境需求:防火墙需要让内网的Ip全部通过,外网IP添加到白名单,其他一切拒绝.安装在linux系统中安装yum install iptables-servic ...

  5. IntelliJ IDEA 基础设置

    原文地址:IntelliJ IDEA 基础设置 博客地址:http://www.extlight.com 一.前言 IDEA 全称 IntelliJ IDEA,是java语言开发的集成环境,Intel ...

  6. 关于responseHeader的一些基础设置

    1.关于响应头的一些基础设置 //设置相应头 response.addHeader("name","zhangsan"); response.addIntHea ...

  7. linux网络基础设置 以及 软件安装

    ifconfig #查看所有已激活的网卡信息 临时配置 #yum install net-tools -y 默认ifconfig是没有安装的,可能需要安装 ifconfig eth0 #查看单独一块网 ...

  8. 项目一:项目第二天 Jquery ztree使用展示菜单数据 2、 基础设置需求分析 3、 搭建项目框架环境--ssh(复习) 4、 SpringData-JPA持久层入门案例(重点) 5、 Easyui menubutton菜单按钮使用 6、 Easyui messager消息框使用

    1. Jquery ztree使用展示菜单数据 2. 基础设置需求分析 3. 搭建项目框架环境--ssh(复习) 4. SpringData-JPA持久层入门案例(重点) 5. Easyui menu ...

  9. 通达OA 小飞鱼工作流在线培训教程(七)工作流应用的意义及基础设置(图文)

    这个课程计划已经有一段时间了,经过这段时间结合实际网络教学又进行了一些总结,这里将陆续为大家呈现相关的工作流设计开发课程. 同一时候线上的视频教学课程也将立即上线,欢迎朋友们的关注. 首先介绍一些工作 ...

随机推荐

  1. CodeFirst写界面——自己写客户端UI库

    何谓CBS程序 CBS程序就是Client+Browser+Service的程序 纯CS程序写界面,有各种难处,那么我就在Client端引入Browser,让Browser渲染基于HTML的UI界面 ...

  2. Cmd命令

    write----------写字板 mspaint--------画图板 mobsync--------同步命令 eudcedit-------造字程序 dvdplay--------DVD播放器 ...

  3. 汇编int21h,DOS调用(转)

    表:DOS系统功能调INT 21H AH 功能 调用参数 返回参数 00 程序终止(同INT 20H) CS=程序段前缀 01 键盘输入并回显 AL=输入字符 02 显示输出 DL=输出字符 03 异 ...

  4. C语言实现二叉树

    二叉树的重要性就不用多说啦: 我以前也学习过,但是一直没有总结: 网上找到的例子,要么是理论一大堆,然后是伪代码实现: 要么是复杂的代码,没有什么解释: 最终,还是靠FQ找到一些好的文章,参考地址我会 ...

  5. Kafka重复消费和丢失数据研究

    Kafka重复消费原因 底层根本原因:已经消费了数据,但是offset没提交. 原因1:强行kill线程,导致消费后的数据,offset没有提交. 原因2:设置offset为自动提交,关闭kafka时 ...

  6. iOS UICollectionView的实现

    ios的UICollectionView并不能在iOS6之前的版本中使用,为了兼容之前的版本需要自定义UICollectionView.写完之后发现人家已经有开源了,下过来看了看发现我是用UIScro ...

  7. nmap端口状态解析

    nmap端口状态解析 状态 说明 open 应用程序在该端口接收 TCP 连接或者 UDP 报文 closed 关闭的端口对于nmap也是可访问的, 它接收nmap探测报文并作出响应.但没有应用程序在 ...

  8. Java开源框架推荐(全)

    Build Tool Tools which handle the buildcycle of an application. Apache Maven - Declarative build and ...

  9. IIS7显示ASP的详细错误信息到浏览器

    服务端环境:Windows2008 + IIS7 客户端浏览器设置:取消“显示友好的HTTP错误信息” IIS7设置(GUI): 1. 网站->ASP->调试属性->将错误发送到浏览 ...

  10. aehyok.com的成长之路一——开篇

    前言   不得不说最近三个月都没更新博客了,除了6月初的一篇博客外,今天的这一篇算是这三个月里发表的第二篇博客了.不过本人几乎每天都在博客园里刷来刷去,看大家发表的博文,从中汲取营养.确实博客园也可以 ...