tabBarItem标题与图片去除渲染
来源:互联网 发布:怎么让4g网络信号增强 编辑:程序博客网 时间:2024/06/05 03:06
我们在使用 UITabBarController 时,会给tabBarItem设置我们自己的图片和标题。但默认情况下,系统会进行渲染,选择tabBarItem的标题和图片会被渲染成蓝色,我们需要将被渲染过的tabBarItem修改成我们想要的样式。
设置子控制器
// 设置子控制器EssenceViewController *essenceVC = [[EssenceViewController alloc] init];UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:essenceVC];// 这个self其实就是UITabBarController,我将其提取了出来封装了个BaseTabBarController,对其子控制器进行管理[self addChildViewController:nav1];
去除图片渲染
UIImage *image = [UIImage imageNamed:@"imageName"];// 去除渲染image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];nav1.tabBarItem.selectedImage = image;
不过,我们可以提取一个Category
// UIImage+image.h@interface UIImage (image)+ (UIImage *)imageOriginalWithName:(NSString *)imageName;@end// UIImage+image.m@implementation UIImage (image)+ (UIImage *)imageOriginalWithName:(NSString *)imageName{ UIImage *image = [UIImage imageNamed:imageName]; return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];}@end
使用时
#import "UIImage+image.h"nav1.tabBarItem.selectedImage = [UIImage imageOriginalWithName:@"tabBar_essence_click_icon"];
去除标题渲染
NSMutableDictionary *attrs = [NSMutableDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, nil];[nav1.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateSelected];
当然,我们有很多个标题,希望可以一次设置所有的标题
+ (void)load{ // 获取某个类中的UITabBarItem // 这个self其实就是UITabBarController,我将其提取了出来封装了个BaseTabBarController,对其子控制器进行管理 UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil]; // 修改title的文字颜色 NSMutableDictionary *attrs = [NSMutableDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, nil]; [item setTitleTextAttributes:attrs forState:UIControlStateSelected]; // 设置字体尺寸:只有设置正常状态下,才会有效果 NSMutableDictionary *attrsNor = [NSMutableDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:13.0],NSFontAttributeName, nil]; [item setTitleTextAttributes:attrsNor forState:UIControlStateNormal];}
0 0
- tabBarItem标题与图片去除渲染
- 设置tabBarItem图片渲染
- 设置tabBarItem的图片渲染
- tabBarItem的图片不要渲染成系统默认的蓝色
- TabBarItem的图片与颜色设置
- Swift中UITabBarController图片去除渲染
- 子控制器tabBarItem底部选中图片显示为自己配置的 不让系统渲染
- tabBarItem设置背景色,标题
- tabbaritem 图片太大解决方案
- tabbaritem 图片太大解决方案
- 图片与图片间距去除
- TabbarItem没有文字,图片居中
- 图片的拉伸与渲染
- 自定义tabBarItem中的图片和文字样式
- uitabbarcontroller上的tabbaritem的图片设置
- IOS7 tabBarItem 自定义图片的设置
- IOS7 tabBarItem 自定义图片的设置
- iOS8 TabBarItem设置自定义图片问题
- Linux下apt方式卸载软件
- 面试记录
- 搜索引擎应用优化技能总结
- Jquery---属性操作
- Codeforces #406 (Div. 2 A. The Monster&B. Not Afraid (暴力
- tabBarItem标题与图片去除渲染
- jQuery选择器之层级选择器
- TP5中Request类可以获得哪些常量信息
- iOS 创建类似遥控器的圆形选择键
- Android五大常用布局
- Android自定义View的实现方法,带你一步步深入了解View
- ffmpeg命令 控制关键帧输出
- POJ3661running
- Linux下两种增加/tmp文件的方法