设为首页 加入收藏

TOP

iOS更改tabbar图片渲染 —不让tabbat有蓝色的渲染 并修改文字(一)
2017-10-13 10:28:41 】 浏览:8177
Tags:iOS 更改 tabbar 图片 渲染 不让 tabbat 蓝色 修改 文字
方式一 
代码实现 这种要写很多代码 ,每个控制器都要写 
 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"
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇悦读FM客户端应用源码 下一篇Swift 数组

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目