1

我正在将图像设置为 UIButton,如下所示:

[fView.coverImage.imageView setImageWithURLRequest:[NSURLRequest requestWithURL:MYURL] placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
                        fView.coverImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
                        [fView.coverImage setImage:image forState:UIControlStateNormal];

}];

有问题的图像的高度为 400 像素。大多数情况下,这工作正常,但在 iPad Retina 屏幕上,UIButton 的高度约为 600 像素。尽管我指定了内容模式,但图像不会放大到 400 像素以上。如何使图像按比例放大超出其原始尺寸?

4

1 回答 1

0

尝试在你的块中使用它:

[ImageManipulation scale:image toSize:fView.coverImage.imageView.frame];

“ImageManipulation”是我的班级名称,随便你怎么称呼它......

这是我用来扩展的方法:

+ (UIImage*)scale: (UIImage*)image toSize: (CGSize)size {
    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}

希望这可以帮助

于 2014-03-11T20:07:07.343 回答