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 = @"aaa";
bTabBarItem.title = @"bbb";
cTabBarItem.title = @"ccc";
dTabBarItem.title = @"ddd";
5.设置tabBar中items的图片
[aTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"aa_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"aa.png"]];
[bTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"bb_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"bb.png"]];
[cTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"cc_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"cc.png"]];
[dTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"dd_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"dd.png"]];
6.设置tabBar的背景图片
// Change the tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbarbg.png"];
[[UITabBar appearance] setBackgroundImage:[tabBarBackground resizableImageWithCapInsets:UIEdgeInsetsZero]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]];
7.改变tabBar中items上字体的颜色
// Change the title color of tab bar items
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor grayColor], UITextAttributeTextColor,
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] forState:UIControlStateHighlighted];
8.将tabBarController加入window中
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
UITabBarController中自定义UITabBar的更多相关文章
- iOS中 UITabBarController中自定义UITabBar
1.创建多个视图控制器,放如UITabBarController中 AViewController *aa = [[AViewController alloc] init]; UINavigation ...
- 自定义UITabBar的两种方式
开发中,经常会遇到各种各样的奇葩设计要求,因为apple提供的UITabBar样式单一,只是简单的"图片+文字"样式,高度49又不可以改变.自定义UITabBar成为了唯一的出路. ...
- iOS之自定义UITabBar替换系统默认的(添加“+”号按钮)
自定义UITabBar替换系统默认的,目的是为了在UITabBar中间位置添加一个“+号按钮”,下面我们来聊聊具体的实现. 1.自定义WBTabBar,让其继承自UITabBar,代码如下: // / ...
- OC和Swift中的UITabBar和UINaviGationBar的适配 [UITabbar在IPad中的适配]
作者 sundays http://www.cnblogs.com/sundaysgarden/ OC中UITabbar的适配[iphoneX和Ipad适配] 自定可以UITabar 自定义UITab ...
- Html中自定义鼠标的形状
Html中自定义鼠标的形状 <html> <head> <title>自定义的鼠标形状</title> <meta http-equiv=&quo ...
- 教你一招:在PowerPoint中自定义可输入文本的占位符
日常生活中,当我们设计多媒体课件时,默认的版式其实已经够用了.但是,很多时候,我们需要更加个性一点,所以,我们需要自定义很多东西.本文介绍在PowerPoint中自定义可输入文本的占位符. 一.占位符 ...
- android代码优化----ListView中自定义adapter的封装(ListView的模板写法)
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- 在Eclipse中自定义类似syso的快捷代码模板
sysout/syso syserr/ syse 点击菜单栏的“Window”->“Preferences”,打开“Preferences”对话框.在Preferences”对话框中点击“Jav ...
- 在.net桌面程序中自定义鼠标光标
有的时候,一个自定义的鼠标光标能给你的程序增色不少.本文这里介绍一下如何在.net桌面程序中自定义鼠标光标.由于.net的桌面程序分为WinForm和WPF两种,这里分别介绍一下. WinForm程序 ...
随机推荐
- Linux 网络编程: gethostbyname( ), getservbyname( )
前言 最近在学习网络编程,用到几个应该比较常用的网络编程函数,所以写篇博客来记录一下,毕竟学得快忘得也快.国庆节在宿舍写着博客看着各个景点人山人海倒也快哉~ gethostbyname( ) 这个函数 ...
- 使用wget -i下载多个文件
使用wget -i下载多个文件 命令: wget -i filelist.txt 说明: 首先,保存一份下载链接文件 cat > filelist.txt url1 url2 url3 url4
- poj 2187 Beauty Contest 最远点距
/** 求出凸包枚举每个点的矩距离即可 因为凸包上的点可定不多.. 学习: 刚开始WA 了一次,,因为用int 存的, 一看discuss 里提供的数据,想起来,,应该是越界了.. 后来用longlo ...
- 【转】页面尺寸不一样的PDF页面调整方法
本文综合参考:http://www.360doc.com/content/10/1114/22/2961363_69395272.shtml http://blog.sina.com.cn/s/blo ...
- C#设置窗体最大化且不遮挡任务栏的方法
C#设置窗体最大化示例: 也可将方法内的内容放到主窗体首次加载load方法中. /// <summary> /// 设置窗体最大化(不遮挡任务栏)但此方法在宽屏中不能显示全屏/// < ...
- WebHdfs
https://github.com/ihrwein/webhdfs https://tiborbenke.blogs.balabit.com/2013/11/the-syslog-ng-in-the ...
- 工程脚本插件方案 - c集成Python基础篇(VC++嵌入Python)
序: 为什么要集成脚本,怎么在工程中集成Python脚本. 在做比较大型的工程时,一般都会分核心层和业务层.核心层要求实现高效和稳定的基础功能,并提供调用接口供业务层调用的一种标准的框架划分.在实际中 ...
- Qt5制作鼠标悬停显示Hint的ToolTip
在日常生活中的使用的软件中,我们经常会遇到这样的情况. 我们在网页上,有些网页链接的文字(比如文章标题,知乎问题标题,百度的词条等)因为太长了,而显示不出来,但是鼠标悬停在上面的时候就可以显示出来. ...
- hibernate 延长加载范围 4.2
1. 关闭延迟加载功能 lazy="false"2.修改抓取策略 fetch="join"直接查询关联数据,一个联接查询搞定3.使用Hibernate对象的in ...
- centos下网络代理服务器的配置
一.临时生效,只在当前用户当前打开的shell终端下生效 在当前控制台下执行如下命令 export http_proxy=http://username:password@proxy_ip:port/ ...