利用代码添加UITabBarController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {ViewController *vc1 = [[ViewController alloc] init];UserGuideViewController *vc2 = [[UserGuideViewController alloc] init];UITabBarController *tabBarController = [[UITabBarController alloc] init];tabBarController.viewControllers = [[NSArray alloc] initWithObjects:vc1, vc2, nil];for(int i=0; i<tabBarController.tabBar.items.count; i++) {UITabBarItem *item = [tabBarController.tabBar.items objectAtIndex:i];item.title = [NSString stringWithFormat:@"子栏目%d",i];NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor],UITextAttributeTextColor, nil];[item setTitleTextAttributes:dict forState:UIControlStateNormal];NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],UITextAttributeTextColor,nil];[item setTitleTextAttributes:dict2 forState:UIControlStateSelected];}self.window.rootViewController = tabBarController;[self.window makeKeyAndVisible];return YES;
}

改变TabBar的背景色

方法一:

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

方法二:

CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();self.tabBar.backgroundImage = image;

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

方法一,改变全局:

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

方法二,改变特定:

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

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

- (void)viewDidLoad {[super viewDidLoad];UIImage *carIcon = [UIImage imageNamed:@"CarIcon"];UIImage *grayCarIcon = [UIImage imageNamed:@"GrayCarIcon"];ViewController *vc1 = [[ViewController alloc] init];UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"栏目A" image:carIcon tag:0];item1.selectedImage = grayCarIcon;vc1.tabBarItem = item1;UserGuideViewController *vc2 = [[UserGuideViewController alloc] init];UITabBarItem *item2 = [[UITabBarItem alloc] initWithTitle:@"栏目B" image:carIcon tag:0];item2.selectedImage = grayCarIcon;vc2.tabBarItem = item2;self.viewControllers = [[NSArray alloc] initWithObjects:vc1, vc2, nil];[self setSelectedViewController:vc2];
}

改变TabBarItem的文本颜色

UITabBarItem *item = self.tabBar.items[0];NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor],UITextAttributeTextColor, nil];
[item setTitleTextAttributes:dict forState:UIControlStateNormal];NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],UITextAttributeTextColor,nil];
[item setTitleTextAttributes:dict2 forState:UIControlStateSelected];

转载于:https://www.cnblogs.com/CoderWayne/p/4226724.html

UITabBarController的一些基础设置相关推荐

  1. SAP PM 初级系列3 - 主数据相关的基础设置

    SAP PM 初级系列3 - 主数据相关的基础设置 1,建立为用户状态授权的授权码 1.1, 该配置的帮助信息, Create Authorization Keys for User Status A ...

  2. wordpress怎么设置文章页面不打开新的窗口_2019 WordPress外贸网站SEO优化基础设置(新手图文教程)...

    做好了网站,选好了主题,配备了必备插件,基础SEO怎么设置才能避免后面经常改动基础设置,导致关键词排名降低,页面收录消失等问题呢? 对于外贸建站老鸟来说,他们装备了插件Yoast SEO的时候,就会把 ...

  3. oracle tax 中国税,oracle_TAX_税基础设置操作手册.doc

    您所在位置:网站首页 > 海量文档 &nbsp>&nbsp计算机&nbsp>&nbsp数据库 oracle_TAX_税基础设置操作手册.doc21页 ...

  4. Eclipse基础设置

    文章目录 Eclipse基础设置 1. 字体设置 2. 更改工作空间及文件类型的默认编码为UTF-8 3. 设置Tab为4个空格 4,设置背景颜色为护眼的豆沙色或更改主题 5. 代码自动提示 6. 窗 ...

  5. amazeui学习笔记--css(基本样式2)--基础设置Base

    amazeui学习笔记--css(基本样式2)--基础设置Base 一.总结 1.盒子模型:外margin,内padding,这里的内外指的边框 2.border-box:Amaze UI 将所有元素 ...

  6. Oracle EBS 寄销/VMI(1)--基础设置;寄销/VMI(2)--采购篇

    名词解释:     BPA:一揽子采购协议     BPR:一揽子发放     SR:来源补充规则     ASL:合格供应商列表     VMI: 供应商管理库存    寄售(Consignment ...

  7. Oracle EBS 寄销/VMI(1)--基础设置

    名词解释:     BPA:一揽子采购协议     BPR:一揽子发放     SR:来源补充规则     ASL:合格供应商列表     VMI: 供应商管理库存 寄售(Consignment)是把 ...

  8. 微信朋友圈营销如何做好头像_昵称_签名_背景基础设置?

    微信朋友圈营销如何做好头像_昵称_签名_背景基础设置? 微信作为营销推广的重要渠道,凭借其出色的私域属性.互动型受到了大家的广泛喜爱.有人做过一项调查,同样的卖货软文信息,在公众号转化率低于20%,可 ...

  9. 企业CMS网站建设第二课:CMS模版开发——CMS基础设置与栏目管理

    知识点:DeDeCMS基础设置.模板管理.网站栏目设置.网站的备份. 1.DeDeCMS基础设置 1.1 DeDeCMS后台 登录后台:在浏览器地址栏输入http://127.0.0.1/dede/  ...

最新文章

  1. 1.12 改善你的模型表现-深度学习第三课《结构化机器学习项目》-Stanford吴恩达教授
  2. flayber正文 再谈如何学习Linux,一线Linux专家学习经验谈
  3. matlab调用opencv的函数
  4. 香港小學一年級入學考試題
  5. jpa 定义中间表实体_Spring Data JPA实体详解
  6. 2020 年,为什么非要采用 DevOps 文化不可?
  7. 源码分析参考:Dupefilter
  8. 百度php笔试题目,12/11/17 百度PHP笔试题目整理
  9. 将语音搜索集成到Google Now中
  10. 04-树6 Complete Binary Search Tree
  11. 交个朋友回应罗永浩3年还清6亿元:争取年底还完
  12. yum mysql my.ini_Centos7 yum安装mysql
  13. 确认取消按钮{删除接口循环返回的数据}
  14. raw转bmp程序c语言,求指导,如何用c语言实现读取*.raw格式图像
  15. 使用微信机器人实现华为OLT和中兴OLT挂测的简单功能
  16. Silktest试用笔记
  17. 【操作系统】结合哲学家进餐问题分析如何预防死锁
  18. 在windows 7上是否可以运行win 10的应用
  19. 磁盘块管理器DiskBlockManager
  20. 谷歌学术+SCI-HUB一键下载SCI文献

热门文章

  1. python怎么向列表中添加内容_Python中向List添加元素方法
  2. 使用c++制作微服务计算服务
  3. python 去掉tab_如何截掉空格(包括tab)
  4. sa密码修改记录_【数据完整性】一文读懂电子记录与电子签名
  5. python xlrd读取excel慢_python操作Excel读写--使用xlrd
  6. toadstool sql格式化
  7. 【kafka】kerberos client is being asked for a password not available to garner authentication informa
  8. 【Elasticsearch】实用BM25 -第2部分:BM25算法及其变量
  9. 【ElasticSearch】Es 源码之 IndicesService 源码解读
  10. 【Es】es 配置文件详解