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

  1. UITabBarController中自定义UITabBar

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

  2. iOS开发 Xcode8中遇到的问题及改动

      iOS开发 Xcode8中遇到的问题及改动 新版本发布总会有很多坑,也会有很多改动. 一个一个填吧... 一.遇到的问题 1.权限以及相关设置 iOS10系统下调用系统相册.相机功能,或者苹果健康 ...

  3. iOS开发——基础篇——iOS开发 Xcode8中遇到的问题及改动

      iOS开发 Xcode8中遇到的问题及改动 新版本发布总会有很多坑,也会有很多改动. 一个一个填吧... 一.遇到的问题 1.权限以及相关设置 iOS10系统下调用系统相册.相机功能,或者苹果健康 ...

  4. OC中UITabBarController控制器

    UITabBarController UITabBarController(记为O)常用于管理多个导航控制器,例如有ABC三个导航控制器,可以:addChildViewController(记为A), ...

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

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

  6. iOS: 在代码中使用Autolayout (2) – intrinsicContentSize和Content Hugging Priority【转】

    原文:http://www.mgenware.com/blog/?p=491 接上文:iOS: 在代码中使用Autolayout (1) – 按比例缩放和优先级. 我们继续来看在代码中使用Autola ...

  7. 在iOS应用程序中使用Frida绕过越狱检测

           阿里聚安全在之前的三篇博客中介绍了利用Frida攻击Android应用程序,整个过程仿佛让开发者开启上帝视角,在本篇博客中,我们将会介绍在iOS应用程序中使用Frida绕过越狱检测.即使 ...

  8. Delphi for iOS开发指南(8):在iOS应用程序中使用Tab组件来显示分页

    Delphi for iOS开发指南(8):在iOS应用程序中使用Tab组件来显示分页 在FireMonkey iOS应用程序中的Tab Tab由FMX.TabControl.TTabControl定 ...

  9. iOS 解决LaunchScreen中图片加载黑屏问题

    iOS 解决LaunchScreen中图片加载黑屏问题 原文: http://blog.csdn.net/chengkaizone/article/details/50478045 iOS 解决Lau ...

随机推荐

  1. mac下怎么删除隐藏文件比如 .Trashes文件

    U盘和移动硬盘接入Mac时会产生.Trashes,.Spotlight-V100,.fseventsd等文件 每插入Mac一次,都会检查是否有这些文件,如果没有,就会创建这些文件 特别是有时候,在文件 ...

  2. Go 完整实现版本比较 VersionCompare 函数

    [转] http://www.syyong.com/Go/Go-implementation-version-comparison-VersionCompare-function.html Versi ...

  3. Java 的异常处理机制

    异常是日常开发中大家都「敬而远之」的一个东西,但实际上几乎每种高级程序设计语言都有自己的异常处理机制,因为无论你是多么厉害的程序员,都不可避免的出错,换句话说:你再牛逼,你也有写出 Bug 的时候. ...

  4. Docker常见仓库Redis

    Redis 基本信息 Redis 是开源的内存 Key-Value 数据库实现. 该仓库提供了 Redis 2.6 ~ 2.8.9 各个版本的镜像. 使用方法 默认会在 6379 端口启动数据库. $ ...

  5. ROS机器人程序设计(原书第2版)补充资料 (拾) 第十章 使用MoveIt!

    ROS机器人程序设计(原书第2版)补充资料 (拾) 第十章 使用MoveIt! 书中,大部分出现hydro的地方,直接替换为indigo或jade或kinetic,即可在对应版本中使用. MoveIt ...

  6. 根据ccid取得账户,更改某段值再创建账户,返回新的ccid

    CREATE OR REPLACE PACKAGE cux_cuxaprebate_utl IS * =============================================== * ...

  7. Scikit-learn:scikit-learn快速教程及实例

    http://blog.csdn.net/pipisorry/article/details/52251305 :7] y = dataset[:,8] 我们将在下面所有的例子里使用这个数据组,换言之 ...

  8. [tornado]使用webscoket的使用总是403错误

    使用的tornado版本为4.0+ 后台: PS D:\CodeHouse\tornado\websocket> python .\ws_app.py WARNING:tornado.acces ...

  9. 阻塞IO服务器模型之多线程服务器模型

    针对单线程服务器模型的特点,我们可以对其进行改进,使之能对多个客户端同时进行响应.最简单的改进即是使用多线程(或多进程)服务器模型,在应用层级别,我们一般采用多线程模式.多线程能让多个客户端同时请求, ...

  10. 在Gazebo中使用DEM構建起伏地形環境

    所需資料下載地址: 1. https://bitbucket.org/osrf/gazebo_tutorials/raw/default/dem/files/ 数字高程模型(致謝谷歌翻譯)概述数字高程 ...