简体   繁体   中英

UIImageView how to cut off Top and Bottom?

My app load an Image in a DetailView. This Detailview is full of information, so I have to win some space. The Image i want to display is really small: 132 × 99 so i have to scale it to the whole width of the screen -> 320 x 240 this looks really big on the screen. So I want to cut the top and the bottom to get 320 x 150 without loosing aspect ratio. I tried: Scale To Fill , Scale To Fit , Center , Aspect To Fill , Aspect To Fit ... in the IB. None was the right. Is there any programmatically way?

EDIT

there are some screenshots
The source:
原版的
Storyboard:
IB
and the ugly version:
streched
my goal (photoshopped):
在此处输入图片说明

Set a necessary size to UIImageView and set it content type to 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.

EDIT

As i understand correctly - it works fine for me, see screenshot from IB:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明 It's a property of UIImageView - it's important to select Aspect Fill , not Scale To Fill

And this work only for UIImageView (not UIButtons)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM