iOS中 UITabBarController中自定义UITabBar
1.创建多个视图控制器,放如UITabBarController中
AViewController *aa = [[AViewController alloc] init];
UINavigationController* ayNav = [[UINavigationController alloc]initWithRootViewController:aa];
BViewController *bb = [[BViewController alloc] init];
UINavigationController* bNav = [[UINavigationController alloc]initWithRootViewController:bb];
CViewController *cc = [[CViewController alloc] init];
UINavigationController* cNav = [[UINavigationController alloc]initWithRootViewController:cc];
DViewController *dd = [[DViewController alloc] init];
UINavigationController* dNav = [[UINavigationController alloc]initWithRootViewController:dd];
2.初始化tabbar
UITabBarController *tabBarController = [[UITabBarController alloc]init];
tabBarController.delegate=self;
tabBarController.viewControllers=[[NSArray alloc]initWithObjects:ayNav,bNav,cNav,dNav,nil];
3.获取到tabBarController中的tabBar,在从tabBar中获取到每个items
UITabBar *tabBar = tabBarController.tabBar; UITabBarItem *aTabBarItem = [tabBar.items objectAtIndex:0]; UITabBarItem *bTabBarItem = [tabBar.items objectAtIndex:1]; UITabBarItem *cTabBarItem = [tabBar.items objectAtIndex:2]; UITabBarItem *dTabBarItem = [tabBar.items objectAtIndex:3];
4. 设置tabBar中items的标题
aTabBarItem.title = @"小韩哥"; bTabBarItem.title = @"iOS编程"; cTabBarItem.title = @"ios开发"; dTabBarItem.title = @"苹果系统";
5.设置tabBar中items的图片
[aTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"aa_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"1.png"]]; [bTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"bb_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"2.png"]]; [cTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"cc_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"3.png"]]; [dTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"dd_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"4.png"]];
6.设置tabBar的背景图片
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar1.png"]; [[UITabBar appearance] setBackgroundImage:[tabBarBackground resizableImageWithCapInsets:UIEdgeInsetsZero]]; [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar.png"]];
7.改变tabBar中items上字体的颜色
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor grayColor], UITextAttributeTextColor,
nil nil] forState:UIControlStateNormal];
UIColor *titleHighlightedColor = [UIColor colorWithRed:153/255.0 green:192/255.0 blue:48/255.0 alpha:1.0];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
titleHighlightedColor, UITextAttributeTextColor,
nil nil] forState:UIControlStateHighlighted];
8.将tabBarController加入window中
self.window.rootViewController = tabBarController; [self.window makeKeyAndVisible];
iOS中 UITabBarController中自定义UITabBar的更多相关文章
- UITabBarController中自定义UITabBar
1.创建多个视图控制器,放如UITabBarController中 AViewController *aa = [[AViewController alloc] init]; UINavigation ...
- iOS开发 Xcode8中遇到的问题及改动
iOS开发 Xcode8中遇到的问题及改动 新版本发布总会有很多坑,也会有很多改动. 一个一个填吧... 一.遇到的问题 1.权限以及相关设置 iOS10系统下调用系统相册.相机功能,或者苹果健康 ...
- iOS开发——基础篇——iOS开发 Xcode8中遇到的问题及改动
iOS开发 Xcode8中遇到的问题及改动 新版本发布总会有很多坑,也会有很多改动. 一个一个填吧... 一.遇到的问题 1.权限以及相关设置 iOS10系统下调用系统相册.相机功能,或者苹果健康 ...
- OC中UITabBarController控制器
UITabBarController UITabBarController(记为O)常用于管理多个导航控制器,例如有ABC三个导航控制器,可以:addChildViewController(记为A), ...
- iOS之自定义UITabBar替换系统默认的(添加“+”号按钮)
自定义UITabBar替换系统默认的,目的是为了在UITabBar中间位置添加一个“+号按钮”,下面我们来聊聊具体的实现. 1.自定义WBTabBar,让其继承自UITabBar,代码如下: // / ...
- iOS: 在代码中使用Autolayout (2) – intrinsicContentSize和Content Hugging Priority【转】
原文:http://www.mgenware.com/blog/?p=491 接上文:iOS: 在代码中使用Autolayout (1) – 按比例缩放和优先级. 我们继续来看在代码中使用Autola ...
- 在iOS应用程序中使用Frida绕过越狱检测
阿里聚安全在之前的三篇博客中介绍了利用Frida攻击Android应用程序,整个过程仿佛让开发者开启上帝视角,在本篇博客中,我们将会介绍在iOS应用程序中使用Frida绕过越狱检测.即使 ...
- Delphi for iOS开发指南(8):在iOS应用程序中使用Tab组件来显示分页
Delphi for iOS开发指南(8):在iOS应用程序中使用Tab组件来显示分页 在FireMonkey iOS应用程序中的Tab Tab由FMX.TabControl.TTabControl定 ...
- iOS 解决LaunchScreen中图片加载黑屏问题
iOS 解决LaunchScreen中图片加载黑屏问题 原文: http://blog.csdn.net/chengkaizone/article/details/50478045 iOS 解决Lau ...
随机推荐
- typeAliases别名
<configuration> <typeAliases> <!-- 通过package, 可以直接指定package的名字, mybatis会自动扫描你指定包下面的ja ...
- javac编译原理
javac编译器的作用就是将符合java语言规范的源代码转化成符合java虚拟机规范的java字节码 经历:词法分析器->语法分析器->语义分析器->编译字节码 四个过程生成字节码文 ...
- 2. struct A 和 typedef struct A
2. struct A 和 typedef struct A 2.1 struct A struct A{}定义一个名为struct A的结构体. 下例定义了struct A同时,声明了两个变量(注意 ...
- POJ 2135 最小费用最大流
题目链接 Farm Tour Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18961 Accepted: 7326 D ...
- Node.js C/C++ 插件
插件 Addons 是动态链接的共享对象.他提供了 C/C++ 类库能力.这些API比较复杂,他包以下几个类库: V8 JavaScript, C++ 类库.用来和 JavaScript 交互,比如创 ...
- jQuery 安装
网页中添加 jQuery 可以通过多种方法在网页中添加 jQuery. 您可以使用以下方法: 从 jquery.com 下载 jQuery 库 从 CDN 中载入 jQuery, 如从 Google ...
- Lucene总结
数据的分类 结构化数据:有固定类型或者有固定长度的数据 例如:数据库中的数据(mysql,oracle等), 元数据(就是windows中的数据) 结构化数据搜索方法: 数据库中数据通过sql语句可以 ...
- Android------Android.mk调用shell脚本
$(info $(shell ($(LOCAL_PATH)/echo_test.sh)))
- 20160215.CCPP体系详解(0025天)
程序片段(01):01.Malloc.c 内容概要:Malloc拓展 #include <stdio.h> #include <stdlib.h> //01.内存伸缩函数: / ...
- Xcode Organizational Identifiers
操作系统(不管是iOS或是OS X)使用bundle标识去唯一标识你的应用.Bundle标识由一个组织id和你App的名字组成. 一般的,组织id是你域名的反转.如果你的域名是example.com那 ...