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];
    [email protected]"精华";
    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];
    [email protected]"新帖";
    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];
    [email protected]"关注";
    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];
    [email protected]"我";
    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];

时间: 2024-08-02 15:10:47

iOS更改tabbar图片渲染 —不让tabbat有蓝色的渲染 并修改文字的相关文章

不让tabbat有蓝色的渲染 并修改文字(iOS更改tabbar图片渲染)

方式一 代码实现 这种要写很多代码 ,每个控制器都要写 UIImage *image=[UIImage imageNamed:@"tabBar_friendTrends_click_icon"]; //    不让tabbar底部有渲染的关键代码 image=[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; vc01.tabBarItem.selectedImage=image; 更改tabbar下方的

iOS 8 TabBar 图片显示真实颜色

“展信颜开” 我怎么想到这个词了呢……因为这个足以表达我现在的心情,有解决了一个问题,有了一个收获. 早上小伙伴问我“用自带的tab改图的颜色他会不显示?改tabitem.”我记得是可以显示的,但是他既然这样问,就肯定是是经过实验的,于是本来相对清闲的我 ,就开始了我的探索旅程 运行过以前的项目之后,我发现要是旧的代码在iOS 8 上面没有了效果首先附上以前的代码 [tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selectI

Android UI之自定义——类似iOS的Tabbar

Android UI之自定义--类似iOS的Tabbar Tabbar最早出现在iOS,iOS中的TabBarController实现了这个功能,开发起来相当简单.现在的APP,大多数都会使用Tabbar来作为应用的功能导航,界面简单清晰.那么Android常见的实现是通过RadioGroup来实现,今天将带来自定义实现,补充RadioGroup实现的不足. 先看看常见的软件中的使用: 这个是高铁管家APP,大家应该非常熟悉.这个APP的首页底部就是一个类似iOS的Tabbar.这里就不多举例子

iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?

Apple官方的文档为生成一个UIImage对象提供了两种方法: 1. imageNamed,其参数为图片的名字: 2. imageWithContentsOfFile,其参数也是图片文件的路径. 那么两种有什么区别吗? 肯定是有的.根据Apple的官方文档: imageNamed: 这个方法用一个指定的名字在系统缓存中查找并返回一个图片对象如果它存在的话.如果缓存中没有找到相应的图片,这个方法从指定的文档中加载然后缓存并返回这个对象.因此imageNamed的优点是当加载时会缓存图片.所以当图

微信更改分享图片和分享链接的方法

1.将以下代码加到head头里 <script>        function htmlEncode(e){return e.replace(/&/g,"&").replace(/ /g," ").replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br />").replace(/&quo

iOS开发基础-图片切换(2)

延续:iOS开发基础-图片切换(1),对(1)里面的代码进行改善. 在 ViewController 类中添加新的数组属性:  @property (nonatomic, strong) NSArray *infoArray; //存放图片信息 通过 self.infoArray 的 getter 方法对其实现初始化(懒加载),其中代码中的 _infoArray 不能用 self.infoArray 替换: 1 //infoArray的get方法 2 - (NSArray *)infoArray

ios学习笔记图片+图片解释(c语言 oc语言 ios控件 ios小项目 ios小功能 swift都有而且笔记完整喔)

下面是目录其中ios文件夹包括了大部分ios控件的介绍和演示,swift的时完整版,可以学习完swift(这个看的是swift刚出来一周的视频截图,可能有点赶,但是完整),c语言和oc语言的也可以完整的学习完所需知识,,其他文件夹的内容如其名说描述一样 没张图片都有文字说明,可以需要该功能的时候搜索一下然后打开图片就可以学习到 网盘下载地址:需要的话给留言我再传上去 http://www.cnblogs.com/langtianya原创 ios学习笔记图片+图片解释(c语言 oc语言 ios控件

iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar 的解决办法

iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar  的解决办法 问题:iOS自定义tabbar后popToRootViewContriller和poptoviewcontroller时出现两个tabbar 1.自定义代码: - (void)viewWillAppear:(BOOL)animated { [super  viewWillAppear:animated]; // 删除系统自动生成的UITabBarB

iOS开发基础-图片切换(3)

延续:iOS开发基础-图片切换(2),对(2)里面的代码用属性列表plist进行改善. 新建 Property List 命名为 Data 获得一个后缀为 .plist 的文件. 按如图修改刚创建的文件: 最后,修改 infoArray 的 getter 方法: 1 //infoArray的getter方法 2 - (NSArray *)infoArray { 3 NSLog(@"需要获取图片信息数组"); 4 //只实例化一次 5 if (_infoArray == nil) { 6