我的应用在DetailView中加载了一个图像。这个Detailview充满了信息,所以我必须赢得一些空间。我想要显示的图像非常小:132 × 99
因此我必须将其缩放到屏幕的整个宽度 - > 320 x 240
这在屏幕上显得非常大。所以我想剪切顶部和底部以获得320 x 150
而不会失去宽高比。我在IB中尝试过:Scale To Fill
,Scale To Fit
,Center
,Aspect To Fill
,Aspect To Fit
...没有人是对的。有任何编程方式吗?
修改
有一些截图
来源:
故事板:
和丑陋的版本:
我的目标(photoshopped):
答案 0 :(得分:1)
为UIImageView设置必要的大小,并将其内容类型设置为UIViewContentModeScaleAspectFill
Scales the content to fill the size of the view.
Some portion of the content may be clipped to fill the view’s bounds.
修改强>
据我理解正确 - 它适用于我,请参阅IB的截图:
这是UIImageView的一个属性 - 选择Aspect Fill
非常重要,而不是Scale To Fill
这只适用于UIImageView(不是UIButtons)