How can I use UIViewContentModeScaleAspectFill for the top

If I do self.imageOfCatalog.Image.contentMode = UIViewContentModeScaleAspectFill;// | UIViewContentModeTop; self.imageOfCatalog.Image.contentMode = UIViewContentModeScaleAspectFill;// | UIViewContentModeTop;

I get what I want with a little cache. It seems like iOS is putting the center of the image.

I want UIImageView to display the top of the image and crop the rest.

How can I do it?

This is a screenshot:

enter image description here

The image is good enough. However, I want the part to appear as the top, not the central part.

+4
source share
1 answer

This is not possible with UIImageView,

  • You will have to subclass UIView
  • Add UIImageview as a property and add it as a preview.
  • set clipToBounds to YES [self setClipsToBounds:YES];
  • Align UIImageView with the top of the view
  • Resize UIImageView based on image proportions in layoutSubviews

An example can be found here .

+8
source

Source: https://habr.com/ru/post/1445366/


All Articles