我试图解决这个问题: 通过规模 2.通过帧大小 3.以及上述两种变体:)
一些代码:
self initWithImage:image //
style: UIBarButtonItemStyleBordered //UIBarButtonItemStylePlain
target:target
action:action
UIImage *image;
image = [[UIImage imageNamed:@“image.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-(UIImage )imageWithImages:(UIImage )image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
请帮帮我。相当简单但棘手的任务。我已经花了几个小时...提前谢谢你:)
答案 0 :(得分:2)
您不应该使用initWithImage方法。 如果要显示确切的图像,则应使用initWithCustomView方法。
例如:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image"]];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:imageView];
如果您愿意,可以在将图像设置为图像视图之前缩小图像。