How can I use UIViewContentModeScaleAspectFill for the top portion

objective-c, uiimageview, xcode

Solution

That's not possible with an UIImageView,

- You'll have to subclass UIView

- Add an UIImageview as a property and add it as subview.

- set clipsToBounds to YES `[self setClipsToBounds:YES];`

- Align the UIImageView to the top of the view

- Resize the UIImageView based on the proportions of the image in layoutSubviews

An example could be found here.

Problem

If I do `self.imageOfCatalog.Image.contentMode = UIViewContentModeScaleAspectFill;// | UIViewContentModeTop;` I get what I want with a small cache. Looks like IOS then put the center of the image. I want the UIImageView to show the top of the image and crop the rest. How would I do so? This is the screenshot: Image is good enough. However, I want the part being shown to be the top part rather than the center part.

Original source