iOS-修改Tabbar选中时候默认渲染成蓝色的状态

来源:互联网 发布:网络计划编制软件 编辑:程序博客网 时间:2024/06/10 20:31

背景

好像我记得iOS6的时候,tabbar里面的东西是不会自动渲染的,也就是说,你设置成怎样显示出来就是怎样。之后的版本tabbar会被渲染,包括文字和图片。默认状态不会被渲染,但是选中状态会被渲染成蓝色。
实际开发中,我们不想让他被渲染,下面讲讲解决渲染的办法。


解决图片渲染问题

找到你的图片在Xcode的位置,然后把Render As的选项修改成Original Image的选项。顾名思义,就是渲染效果是原始图片的效果,即不做渲染。

这里写图片描述


解决文字渲染的问题

文字渲染,这个就需要写代码来解决了。当然了,解决图片渲染的问题,也可以通过代码来解决。

 NSMutableDictionary *attributes = [NSMutableDictionary dictionary];    attributes[NSForegroundColorAttributeName] = [UIColor lightGrayColor];    attributes[NSFontAttributeName] = [UIFont systemFontOfSize:11];    NSMutableDictionary *selectAttri = [NSMutableDictionary dictionary];    selectAttri[NSForegroundColorAttributeName] = [UIColor darkGrayColor];    selectAttri[NSFontAttributeName] = [UIFont systemFontOfSize:11];    //通过appearance对tabBarItem的文字属性进行统一设置,这样所有的控制的tabBarItem的文字属性久都是这种样式的了    UITabBarItem *tabbar = [UITabBarItem appearance];    [tabbar setTitleTextAttributes:attributes forState:UIControlStateNormal];    [tabbar setTitleTextAttributes:selectAttri forState:UIControlStateSelected];

这种设置方法,是把tabbar的所有按钮状态全部改成一样的设置。如果你想点击不同按钮,出来的效果不一样,那么就分别设置每个控制器的tabBarItem。

NSMutableDictionary *attributes = [NSMutableDictionary dictionary];//颜色属性attributes[NSForegroundColorAttributeName] = [UIColor lightGrayColor];//字体大小属性//还有一些其他属性的key可以去NSAttributedString.h文件里去找attributes[NSFontAttributeName] = [UIFont systemFontOfSize:13];NSMutableDictionary *selectAttri = [NSMutableDictionary dictionary];selectAttri[NSForegroundColorAttributeName] = [UIColor darkGrayColor];selectAttri[NSFontAttributeName] = [UIFont systemFontOfSize:13];UIViewController *vc1 = [[UIViewController alloc] init];vc1.tabBarItem.title = @"首页";//设置为选中状态的文字属性[vc1.tabBarItem setTitleTextAttributes:attributes forState:UIControlStateNormal];//设置选中状态的属性[vc1.tabBarItem setTitleTextAttributes:selectAttri forState:UIControlStateSelected];vc1.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];vc1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
阅读全文
3 0
原创粉丝点击