代码语言: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);
}
}