在 UIImageView 中拟合 UIImage [英] Fitting a UIImage in UIImageView

查看:67
本文介绍了在 UIImageView 中拟合 UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据 UIImageView 的大小调整我的 UIImage 的大小.我的图片太小了,所以我需要放大它.我无法使用:

I need to resize my UIImage according to the size of UIImageView. My image is too small, so i need to scale it up. I was not able to do it using:

self.firstImage.contentMode = UIViewContentModeScaleAspectFit;

请帮忙.

推荐答案

您只需要设置 UIImageView 的框架并将 contentMode 设置为调整大小之一选项.

You just need to set the frame of your UIImageView and set the contentMode to one of the resizing options.

或者您可以使用此实用方法,如果您确实需要调整图像大小:

Or you can use this utility method, if you actually need to resize an image:

+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    //UIGraphicsBeginImageContext(newSize);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}

或者看看这些链接:

http://nanostuffs.com/Blog/?p=586

http://www.abdus.me/ios-programming-tips/resize-image-in-ios/

这篇关于在 UIImageView 中拟合 UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆