指定显示区域,单位为1
CGRectMake(0.25,0.25,0.5,0.5) ->就是显示正中间的区域 宽度高度为一半
int width = image.size.width;
int height = image.size.height;
CGFloat scale = (height / width) / (self.height / self.width);
if (scale < 0.99 || isnan(scale)) {
// 宽图把左右两边裁掉
self.contentMode = UIViewContentModeScaleAspectFill;
self.layer.contentsRect = CGRectMake(0, 0, 1, 1);
} else {
// 高图保留中间
self.contentMode = UIViewContentModeScaleToFill;
CGFloat showScale = (float)width / height;
self.layer.contentsRect = showScale > 1.0 ? CGRectMake(0, 0, 1, 1) : CGRectMake(0, (1-showScale)*0.5, 1, showScale);
}
网友评论