如果UIImageView尺寸写死了,那么针对不同的图片,如果属性设置为填充整个UIImageView, 那么图片自然就会被拉伸,效果很不好
有一个好方法,既可以把UIImageView尺寸写死,又可以让图片显示自然
就是把mode设置成 Aspect Fit, 图片就会根据自己本身的尺寸跟UIImageView的尺寸算出显示的比例,这样UIImageView尺寸固定了,但是图片显示时就会居中且等比例的放大缩小.
imagerootview.contentMode = UIViewContentModeScaleAspectFit;
// contents scaled to fit with fixed aspect. remainder is transparent 内容进行缩放以适合与固定纵横。其余部分是透明的。
UIViewContentModeScaleAspectFill,
// contents scaled to fill with fixed aspect. some portion of content may be clipped.