遇到问题 设置了一个宽高 固定的(1:1 )的 图片 用 sdwebimage 加载的时候显示出来的图片会被压缩或者拉伸,想让显示 一部分的图片(保持图片不变形) 所以对图片进行剪裁代码如下
[cell.imagesd_setImageWithURL:imageUrl placeholderImage:[UIImageimageNamed:@"futrue"] completed:^(UIImage *image,NSError *error, SDImageCacheType cacheType,NSURL *imageURL) {
CGSize newSize;
CGImageRef imageRef =nil;
if ((image.size.width / image.size.height) < 1) {
newSize.width = image.size.width;
newSize.height = image.size.width ;
imageRef = CGImageCreateWithImageInRect([imageCGImage], CGRectMake(0,fabs(image.size.height - newSize.height) / 2, newSize.width, newSize.height));
} else {
newSize.height = image.size.height;
newSize.width = image.size.height *1;
imageRef = CGImageCreateWithImageInRect([imageCGImage], CGRectMake(fabs(image.size.width - newSize.width) / 2, 0, newSize.width, newSize.height));
}
cell.image.image =[UIImageimageWithCGImage:imageRef];
}];
后来发现对 iimageView 做入下处理 就可实现
showSpecialityCatoryImage.contentMode =UIViewContentModeScaleAspectFill;
showSpecialityCatoryImage.clipsToBounds = YES