Search code examples
iosxcodeuiscrollview

Adding an image with a specific aspect ratio to a ScrollView


I am trying to add a compound component to a scroll view but keeping the aspect ratio of the component the same. I have the top and bottom of the compound component constrained to parent and have constrained the aspect ratio. The issue that I have is that the scroll view does not know what the width of the compound component is so it chops off what ever is not on the screen. is there a way to make the Scroll View not chop off the leading and trailing edges of the compound component while preserving the aspect ratio of the image? Screenshot of the autolayout


Solution

  • I Found a solution to my problem. What I did was change the constraints so that the leading and trailing edges were constrained instead of the top and bottom. I then played around with the aspect ratio until I got everything to fit properly. I also set the content mode to scale to fill.