iOS 获取UIImageView缩放后的图片Size

2019-07-25 16:51:09 浏览数 (1)

代码语言:javascript复制
 (CGSize)imageSizeAfterAspectFit:(UIImageView*)imageView
{
    float imageRatio = imageView.image.size.width / imageView.image.size.height;
    float viewRatio = imageView.frame.size.width / imageView.frame.size.height;
    if(imageRatio < viewRatio)
    {
        float scale = imageView.frame.size.height / imageView.image.size.height;
        float width = scale * imageView.image.size.width;
        return CGSizeMake(width, imageView.frame.size.height);
    }
    else
    {
        float scale = imageView.frame.size.width / imageView.image.size.width;
        float height = scale * imageView.image.size.height;
        return CGSizeMake(imageView.frame.size.width, height);
    }
}

0 人点赞