0

enter image description here

I have a UIImageView and a UILabel.

I have added leading and trailing constraints to the margin in the storyboard.

I am setting the image in the image view from an array of images each of which is of different size.

The images are aspect fit to the image view , so there is space on right and left of the image view if the image is smaller than the imageview.

How can I scale an image such that the image view resizes itself based on the size of the image and there is no empty space in the background?

I tried adding a height constraint and changing the constant value in the code . I have tried most of the solutions online , but hasn't worked.

Any help will be appreciated thank you.

A.S
  • 798
  • 1
  • 10
  • 32

1 Answers1

1

set imageview content mode to centre and remove leading and trailing Layout instead you can use horizontal and vertical centre layout.

Ashok
  • 180
  • 1
  • 7