有些图片显示出来会自动渲染成蓝色
比如
- 设置tabBarItem的选中图片
vc.tabBarItem.selectedImage = image;
- 设置UIButtonTypeSystem样式按钮的image时
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setImage:image forState:UIControlStateNormal];
解决方案
- 再次产生一张不会进行渲染的图片
// 加载图片
UIImage *tempImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
// 产生一张不会进行自动渲染的图片
UIImage *selectedImage = [tempImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
vc.tabBarItem.selectedImage = selectedImage;
-
直接在xcassets文件中配置
当然我们可以个UIImage添加一个分类将功能封装起来
在.h文件
#import <UIKit/UIKit.h>
@interface UIImage (Image)
+ (UIImage *)imageOriginalWithName:(NSString *)imageName;
@end
在.m文件
#import "UIImage+Image.h"
@implementation UIImage (Image)
+ (UIImage *)imageOriginalWithName:(NSString *)imageName
{
UIImage *image = [UIImage imageNamed:imageName];
return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
@end