转发:http://www.cnblogs.com/qianLL/p/5521228.html
 
方式一 
代码实现 这种要写很多代码 ,每个控制器都要写 
 UIImage *image=[UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
//    不让tabbar底部有渲染的关键代码
     image=[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc01.tabBarItem.selectedImage=image;
 
更改tabbar下方的文字样式,大小, 颜色
  NSMutableDictionary *atts=[NSMutableDictionary dictionary];
// 更改文字大小
    atts[NSFontAttributeName]=[UIFont systemFontOfSize:12];
// 更改文字颜色
    atts[NSForegroundColorAttributeName]=[UIColor darkGrayColor];
 
    NSMutableDictionary *selectedAtts=[NSMutableDictionary dictionary];
    selectedAtts[NSFontAttributeName]=[UIFont systemFontOfSize:12];
    selectedAtts[NSForegroundColorAttributeName]=[UIColor greenColor];
    [vc01.tabBarItem setTitleTextAttributes:selectedAtts forState:UIControlStateSelected];
 
 
方式二  
 
在 Assets.xcassets文件夹中更改 改变之后不用代码  并且在所有的控制器里面都会被作用到
具体操作
 
appearance属性
//    通过appearance统一设置所有的UITabBarItem的文字属性
//    后面带有UI_APPEARANCE_SELECTOR的方法,都可以通过appearance同意设置
例如UITabBarItem的文字属性
案例; 
    NSMutableDictionary *atts=[NSMutableDictionary dictionary];
    atts[NSFontAttributeName]=[UIFont systemFontOfSize:12];
    atts[NSForegroundColorAttributeName]=[UIColor grayColor];
   
    NSMutableDictionary *selectedAtts=[NSMutableDictionary dictionary];
    selectedAtts[NSFontAttributeName]=atts[NSFontAttributeName];
    selectedAtts[NSForegroundColorAttributeName]=[UIColor darkGrayColor];
// 在这里 只要更改,所有的文字都改
 
    UITabBarItem *item=[UITabBarItem appearance];
    [item setTitleTextAttributes:atts forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAtts forState:UIControlStateSelected];
   
    //    添加子控制器
    UIViewController *vc01=[[UIViewController alloc]init];
    vc01.view.backgroundColor=[UIColor redColor];
    vc01.tabBarItem.title=@"精华";
    vc01.tabBarItem.image=[UIImage imageNamed:@"tabBar_essence_icon"];
    UIImage *image=[UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
//    不让tabbar底部有渲染的关键代码
     image=[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc01.tabBarItem.selectedImage=image;
// 把控制器 添加到 UITabBarController里面去
    [self addChildViewController:vc01];
   
    UIViewController *vc02=[[UIViewController alloc]init];
    vc02.tabBarItem.title=@"新帖";
    vc02.tabBarItem.image=[UIImage imageNamed:@"tabBar_new_click_icon"];
    vc02.tabBarItem.selectedImage=[UIImage imageNamed:@"tabBar_new_click_icon"];
    vc02.view.backgroundColor=[UIColor cyanColor];
    [self addChildViewController:vc02];
   
    UIViewController *vc03=[[UIViewController alloc]init];
    vc03.view.backgroundColor=[UIColor blueColor];
    vc03.tabBarItem.title=@"关注";
    vc03.tabBarItem.image=[UIImage imageNamed:@"tabBar_friendTrends_icon"];
    vc03.tabBarItem.selectedImage=[UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
    [self addChildViewController:vc03];
   
    UIViewController *vc04=[[UIViewController alloc]init];
    vc04.tabBarItem.title=@"我";
    vc04.tabBarItem.image=[UIImage imageNamed:@"tabBar_me_icon"];
    vc04.tabBarItem.selectedImage=[UIImage imageNamed:@"tabBar_me_click_icon"];
    vc04.view.backgroundColor=[UIColor yellowColor];
    [self addChildViewController:vc04];

最新文章

  1. Redis 支持的5种数据结构
  2. Html中代码换行造成空格间距的问题
  3. Asp.Net MVC 使用Entity Framework创建模型类
  4. js键盘操作事件
  5. Gym 100531H Problem H. Hiking in the Hills 二分
  6. Mac Vim 如何设置高亮
  7. c#抽象工厂模式
  8. IT痴汉的工作现状16-职业发展
  9. nginx域名跳转技巧
  10. vs 修改活动解决方案配置后无法调试,不生成pdb文件,“当前不会命中断点 还没有为该文档加载任何符号” 解决方法
  11. 2017-10-29—英语发音的一些技巧总结
  12. Android——线程通讯 Handler、Looper、Message;
  13. vue-router 如何默认显示三级子路由
  14. NHibernate:no persister for 异常
  15. 20175316 盛茂淞 实验一 Java开发环境的熟悉
  16. [k8s]jenkins配合kubernetes插件实现k8s集群构建的持续集成
  17. springboot 增加过滤器方法
  18. 【学习笔记】python的代码块(吐槽)
  19. why go
  20. Java基础2-容器篇

热门文章

  1. Redis4- llist的操作
  2. POJ 3737/三分
  3. Android Binder机制原理(史上最强理解,没有之一)(转)
  4. HDU 5806 NanoApe Loves Sequence Ⅱ
  5. 总结的git操作命令小抄集
  6. WKWebView与Js交互
  7. 递归解析任意层的json
  8. hdu_2446_Shell Pyramid(数学,二分)
  9. TextBox只读时不能通过后台赋值取值解决办法
  10. mybatis 做 insert操作的时候返回插入的那条数据的id