UIImageView如何切断顶部和底部?

时间:2013-04-29 13:16:05

标签: iphone ios objective-c uiimageview

我的应用在DetailView中加载了一个图像。这个Detailview充满了信息,所以我必须赢得一些空间。我想要显示的图像非常小:132 × 99因此我必须将其缩放到屏幕的整个宽度 - > 320 x 240这在屏幕上显得非常大。所以我想剪切顶部和底部以获得320 x 150而不会失去宽高比。我在IB中尝试过:Scale To FillScale To FitCenterAspect To FillAspect To Fit ...没有人是对的。有任何编程方式吗?

修改

有一些截图 来源:
original
故事板:
IB
和丑陋的版本:
streched
我的目标(photoshopped):
enter image description here

1 个答案:

答案 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的截图:

enter image description here

enter image description here

enter image description here这是UIImageView的一个属性 - 选择Aspect Fill非常重要,而不是Scale To Fill

这只适用于UIImageView(不是UIButtons)