0

I've created the image view and set the image dynamically based on the API response. I've set the image and constraints programmatically and didn't use any storyboard files. Currently I am setting the content mode of the image view. Now I want to set the ratio value to 21:9 to the image programmatically. Is that possible to give the ratio value to the image?

Thanks in Advance!

Devan
  • 147
  • 1
  • 1
  • 8
  • It sounds like you want to set ratio to ImageView via constraints to 21:9? If you want to operate on image you should crop it then – Lu_ Jun 04 '19 at 06:56
  • Maybe this one helps you https://stackoverflow.com/a/43414400/10150796 – Nikunj Kumbhani Jun 04 '19 at 06:59
  • Possible duplicate of [How can I set aspect ratio constraints programmatically in iOS?](https://stackoverflow.com/questions/31334017/how-can-i-set-aspect-ratio-constraints-programmatically-in-ios) – Harsh Pipaliya Jun 04 '19 at 07:00

1 Answers1

0

You could use:

imageView.heightAnchor.constraint(equalTo: imageView.widthAnchor, multiplier: 21/9).isActive = true
Marwen Doukh
  • 1,946
  • 17
  • 26