网络图片下载以后,不能完全平铺到UIImageView上面,需要所一定的裁剪
- (UIImage *)handleImage:(UIImage *)originalImage
{
CGSize newSize;
CGImageRef imageRef =nil;
if ((originalImage.size.width / originalImage.size.height) < (imageView.frame.size.width / imageView.frame.size.height)) {
newSize.width = originalImage.size.width;
newSize.height = originalImage.size.width *self.height /self.width;
imageRef = CGImageCreateWithImageInRect([originalImageCGImage], CGRectMake(0,fabs(originalImage.size.height - newSize.height) / 2, newSize.width, newSize.height));
} else {
newSize.height = originalImage.size.height;
newSize.width = originalImage.size.height *self.width /self.height;
imageRef = CGImageCreateWithImageInRect([originalImageCGImage], CGRectMake(fabs(originalImage.size.width - newSize.width) / 2, 0, newSize.width, newSize.height));
}
return [UIImageimageWithCGImage:imageRef];
}
这样就可以裁剪出相同比例的图片,然后平铺到UIImageView上面,就不会出现拉伸变形注意:裁剪有可能会出现图片不全,如果图片比例和UIImageView宽高比例过大,裁剪的也会比较多新闻热点
疑难解答