一般情况 设置背景图片 颜色会被修改
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[UIImage imageWithData:data] style:UIBarButtonItemStyleDone target:self action:nil];
//修改图片模式后 正常了
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageWithData:data]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:nil];
//修正图片的大小
-
(UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize
{
UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));
[image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();return [reSizeImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
//最终使用
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[self reSizeImage:[UIImage imageWithData:data] toSize:CGSizeMake(40, 40)] style:UIBarButtonItemStyleDone target:self action:nil];
网友评论