I have an image inside of a UIScrollView. The Image's length is much larger then the device screen size and that is why i placed it in a scrollview. However, to avoid clipping and distortion of the image I have the constraints set so the image will always have the correct aspect ratio. When you run this on different size screens, the image is different sizes. Now I want to be able to have the scrollview be the same size as my image so that the scrollview is never bigger then the image itself. Is there some code I can program in to make my scrollview always the same height as my image? I need my scrollview to change depending on the height of the image since on different devices the height of my image will change.
so far I have:
class Second : UIViewController {
@IBOutlet weak var myScrollView: UIScrollView!
@IBOutlet weak var myImage: UIImageView!
override func viewDidLoad() {
ScrollView.contentSize.height = 1300
}
The constraints I used on the image are:
- Equal width as the scrollview
- entered horizontally in the scrollview
- Top space to the top of the scrollview
- Aspect fit (so the image is not distorted)
Thank you. Any help is very appreciated!