星空网 > 软件开发 > 操作系统

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文件夹中更改 改变之后不用代码  并且在所有的控制器里面都会被作用到
具体操作
iOS更改tabbar图片渲染 —不让tabbat有蓝色的渲染 并修改文字
 
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];



原标题:iOS更改tabbar图片渲染 —不让tabbat有蓝色的渲染 并修改文字

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

深圳马来西亚专线:https://www.goluckyvip.com/tag/90832.html
深圳到马来西亚快递专线:https://www.goluckyvip.com/tag/90833.html
上海到马来西亚物流货运专线:https://www.goluckyvip.com/tag/90834.html
马来西亚运货到中国:https://www.goluckyvip.com/tag/90835.html
中国到马来西亚发货:https://www.goluckyvip.com/tag/90836.html
马来西亚集运到中国:https://www.goluckyvip.com/tag/90837.html
武陵山大裂谷周围景点 武陵山大裂谷周围景点图片:https://www.vstour.cn/a/411233.html
南美旅游报价(探索南美洲的旅行费用):https://www.vstour.cn/a/411234.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流