iOS去除系统默认的图片和文字的渲染
Posted PJXWang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS去除系统默认的图片和文字的渲染相关的知识,希望对你有一定的参考价值。
1.去除图片的系统默认渲染
选中图片,设置属性Render As为Original Image
代码控制:
#import <UIKit/UIKit.h>
@interface UIImage (HKExtension)
@property(nonatomic,strong,readonly)UIImage * resizbleImage;
@property(nonatomic,strong,readonly)UIImage * originarImage;
+(UIImage *)hk_resizbleImage:(NSString *)name;
+(UIImage *)imageWithOriginalNamed:(NSString *)name ;
+(UIImage *)hk_imageWithOriginalNamed:(NSString *)name;
@end
#import "UIImage+HKExtension.h"
@implementation UIImage (HKExtension)
//不被渲染
-(UIImage *)originarImage
{
return [self imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
+(UIImage *)hk_imageWithOriginalNamed:(NSString *)name
{
UIImage * image = [UIImage imageNamed:name];
return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
//不被渲染
+(UIImage *)imageWithOriginalNamed:(NSString *)name
{
UIImage * image = [UIImage imageNamed:name];
return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
//保护四周 拉伸中间一个像素点
+(UIImage *)hk_resizbleImage:(NSString *)name
{
UIImage * image = [UIImage imageNamed:name];
return [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
}
@end
2.去除文字渲染
//设置应用程序中所有的UITabBarItem的属性
UITabBarItem * item = [UITabBarItem appearance];//认为是一个皮肤
//属性字典
NSDictionary * dict = @{
NSFontAttributeName : [UIFont systemFontOfSize:12],
NSForegroundColorAttributeName : [UIColor grayColor]
};
NSDictionary * dictSelect = @{ NSForegroundColorAttributeName : [UIColor darkGrayColor]};
[item setTitleTextAttributes:dict forState:UIControlStateNormal];
[item setTitleTextAttributes:dictSelect forState:UIControlStateSelected];
注意:文字在选中状态下字体大小设置没有用,文字大小只能在normal状态下设置
以上是关于iOS去除系统默认的图片和文字的渲染的主要内容,如果未能解决你的问题,请参考以下文章
OC - 使用 系统自己的UITabBarController 出现selectedImage的颜色为默认蓝色