1.UIImageView的属性就可以实现中心裁剪 只需要两句代码 xib也可以找到对应属性直接设置
ImageView.contentMode = UIViewContentModeScaleAspectFill;
ImageView.clipsToBounds = YES;
2.SDWebImg 下载图片后裁剪
[_imageView sd_setImageWithURL:[NSURL URLWithString:_model.imgUrlList[0]] placeholderImage:[UIImage imageNamed:@"placeholderImage"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (image != nil) {
if (image.size.height > image.size.width) {//图片的高大于与宽时
CGFloat width = image.size.width/_imageView.size.width;
// CGFloat height = image.size.height/_imageView.size.height; 根据需求自行设置
CGRect rect = CGRectMake(0, 0, _imageView.size.width*width, _imageView.size.height*width);//创建矩形框
CGImageRef cgimg = CGImageCreateWithImageInRect([image CGImage], rect);
_VideoView.image=[UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);
}
}
}];