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的更多相关文章

  1. iOS中 UITabBarController中自定义UITabBar

    1.创建多个视图控制器,放如UITabBarController中 AViewController *aa = [[AViewController alloc] init]; UINavigation ...

  2. 自定义UITabBar的两种方式

    开发中,经常会遇到各种各样的奇葩设计要求,因为apple提供的UITabBar样式单一,只是简单的"图片+文字"样式,高度49又不可以改变.自定义UITabBar成为了唯一的出路. ...

  3. iOS之自定义UITabBar替换系统默认的(添加“+”号按钮)

    自定义UITabBar替换系统默认的,目的是为了在UITabBar中间位置添加一个“+号按钮”,下面我们来聊聊具体的实现. 1.自定义WBTabBar,让其继承自UITabBar,代码如下: // / ...

  4. OC和Swift中的UITabBar和UINaviGationBar的适配 [UITabbar在IPad中的适配]

    作者 sundays http://www.cnblogs.com/sundaysgarden/ OC中UITabbar的适配[iphoneX和Ipad适配] 自定可以UITabar 自定义UITab ...

  5. Html中自定义鼠标的形状

    Html中自定义鼠标的形状 <html> <head> <title>自定义的鼠标形状</title> <meta http-equiv=&quo ...

  6. 教你一招:在PowerPoint中自定义可输入文本的占位符

    日常生活中,当我们设计多媒体课件时,默认的版式其实已经够用了.但是,很多时候,我们需要更加个性一点,所以,我们需要自定义很多东西.本文介绍在PowerPoint中自定义可输入文本的占位符. 一.占位符 ...

  7. android代码优化----ListView中自定义adapter的封装(ListView的模板写法)

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  8. 在Eclipse中自定义类似syso的快捷代码模板

    sysout/syso syserr/ syse 点击菜单栏的“Window”->“Preferences”,打开“Preferences”对话框.在Preferences”对话框中点击“Jav ...

  9. 在.net桌面程序中自定义鼠标光标

    有的时候,一个自定义的鼠标光标能给你的程序增色不少.本文这里介绍一下如何在.net桌面程序中自定义鼠标光标.由于.net的桌面程序分为WinForm和WPF两种,这里分别介绍一下. WinForm程序 ...

随机推荐

  1. 「OC」内存管理

    一.基本原理 (一)为什么要进行内存管理. 由于移动设备的内存极其有限,所以每个APP所占的内存也是有限制的,当app所占用的内存较多时,系统就会发出内存警告,这时需要回收一些不需要再继续使用的内存空 ...

  2. Software Version --hdu1976

    #include using namespace std; int main() { int T; cin>>T; int a1,b1,c1; int a2,b2,c2; while(T- ...

  3. XWalkView+html 开发Android应用

    在Android开发中有时候为了开发简洁和方便移植,采用了Html+WebView的开发模式,然而Android自带的WebView控件是调用的本机的浏览器内核,有些版本较老的手机浏览器和手机性能都不 ...

  4. ie条件注释还能这样写

    通过条件注释给html开始标签定义不同的class, 来区分不同版本的IE,可以在样式表中避免 样式属性hack (如 _margin-top, *float:none ) 注意: IE10+不支持条 ...

  5. nginx的 CPU参数worker_processes和worker_cpu_affinity使用说明

    官方说明: http://wiki.nginx.org/NginxChsHttpMainModule#worker_cpu_affinity http://wiki.nginx.org/NginxCh ...

  6. Android Paint、Canvas、Matrix使用讲解(一、Paint)

    http://blog.csdn.net/tianjian4592/article/details/44336949 好了,前面主要讲了Animation,Animator 的使用,以及桌面火箭效果和 ...

  7. 自己动手为PHP7添加新的语法特性

    好文章! nikic介绍了如何向PHP添加新的语法特性,原文写的非常精彩,具体是添加in语法功能,使最终实现: <?php $words = ['hello', 'world', 'foo', ...

  8. Keil4 每次选build 编译(F7)都全部编译的解决办法

    Keil4 每次选build 编译(F7)都全部编译的解决办法 http://blog.csdn.net/wchengshen/article/details/50440079 Keil4 每次选bu ...

  9. [转]Windows7 64bit下配置Apache+PHP+MySQL

    原文链接:http://blog.csdn.net/sbz0409/article/details/12946375 1.准备资料: 首先下载文件:Apache2.4.16 64bit,http:// ...

  10. 版本管理神器git上手

    由于以前折腾过svn,虽然最终没有用成功,但是也算有经验,git入门还是比较简单的. 在新目录下建立初始化版本库  : git init git add file git add file2 git ...