Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use UIViewContentModeScaleAspectFill for the top portion [closed]

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:

enter image description here

Image is good enough. However, I want the part being shown to be the top part rather than the center part.

like image 891
user4951 Avatar asked Jan 15 '23 01:01

user4951


1 Answers

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.

like image 119
Tieme Avatar answered Jan 25 '23 16:01

Tieme