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. Joel在耶鲁大学的演讲

    Joel Spolsky是一个美国的软件工程师,他的网络日志"Joel谈软件"(Joel on Software)非常有名,读者人数可以排进全世界前100名. 上个月28号,他回到 ...

  2. 创建js对象和js类

    //第一种定义方式 var person=new Object(); //创建了一个对象. person.name="tom"; //使用person对象对调用name属性,它的值 ...

  3. python多线程实现售票

    转载或借鉴请注明转自http://www.cnblogs.com/FG123/p/5068386.html  谢谢! 我们使用mutex(Python中的Lock类对象)来实现线程的同步: lock. ...

  4. Java多线程实现......(1,继承Thread类)

    MyThread.java 中的代码: public class MyThread extends Thread{ private int startPrint,printCount; private ...

  5. VCC、VDD、VEE、VSS的区别

    电路设计以及PCB制作中,经常碰见电源符号:VCC. VDD.VEE.VSS,他们具有什么样的关系那? 一.解释 VCC:C=circuit 表示电路的意思, 即接入电路的电压 VDD:D=devic ...

  6. QR码生成原理

    一.什么是QR码 QR码属于矩阵式二维码中的一个种类,由DENSO(日本电装)公司开发,由JIS和ISO将其标准化.QR码的样子其实在很多场合已经能够被看到了,我这还是贴个图展示一下: 这个图如果被正 ...

  7. HttpGet()和HttpPost()

    转 http://www.cnblogs.com/hyddd/archive/2009/03/31/1426026.html Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,P ...

  8. 安装好maven后,在cmd中运行mvn报一下的错误

    当然报错,你这个路径下并没有pom.xml文件.你可以运行这个命令: mvn -version.

  9. PROPAGATION_REQUIRED

    PROPAGATION_REQUIRED (2009-05-13 13:26:52) 转载▼   事务传播行为种类 Spring在TransactionDefinition接口中规定了7种类型的事务传 ...

  10. Java 输出通过 InetAddress 获得的 IP 地址数组

    使用 InetAddress 获取 IP 地址会得到一个 byte 数组 如果你直接输出这个数组,你会发现 IP 地址中的某些位变成了负数 比如 61.135.169.105 会输出成 61.-121 ...