Image ScrollView

Hello, I have a ScrollView with images, but the images do not fit the size of my ScrollView. Before updating in Xcode8, the scroll was done correctly, exactly suitable size and perfect paging. below the code that manages the scroll. anyone have any idea on how to properly adapt my images to the size of the scroll. thank you

`class GoaLawahViewController: UIViewController, UIScrollViewDelegate {

@IBOutlet weak var menuButton: UIBarButtonItem!

@IBOutlet weak var ScrollView: UIScrollView!

@IBOutlet weak var PageControl: UIPageControl!


override func viewDidLoad() {
    super.viewDidLoad()
    
    let ScrollViewWidth:CGFloat = self.ScrollView.frame.width
    let scrollViewHeight:CGFloat = self.ScrollView.frame.height
    
    
    let imgOne = UIImageView(frame: CGRect(x: 0, y: 0,width: ScrollViewWidth, height: scrollViewHeight))
    imgOne.image = UIImage(named: "GoaLawah04.jpg")
    let imgTwo = UIImageView(frame: CGRect(x: ScrollViewWidth, y: 0,width: ScrollViewWidth, height: scrollViewHeight))
    imgTwo.image = UIImage(named: "GoaLawah07.jpg")
    let imgThree = UIImageView(frame: CGRect(x: ScrollViewWidth, y: 0,width: ScrollViewWidth, height: scrollViewHeight))
    imgThree.image = UIImage(named: "GoaLawah09.jpg")
    
    
    self.ScrollView.addSubview(imgOne)
    self.ScrollView.addSubview(imgTwo)
    self.ScrollView.addSubview(imgThree)
    
    
    self.ScrollView.contentSize = CGSize(width: self.ScrollView.frame.width * 3, height: 1.0)
    self.ScrollView.delegate = self
    self.PageControl.currentPage = 0
    
    
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView){
    // Test the offset and calculate the current page after scrolling ends
    let pageWidth:CGFloat = scrollView.frame.width
    let currentPage:CGFloat = floor((scrollView.contentOffset.x-pageWidth/2)/pageWidth)+1
    // Change the indicator
    self.PageControl.currentPage = Int(currentPage);
    
    
}

}
`

You have to do some changes :

let imgOne = UIImageView(frame: CGRect(x: 0, y: 0,width: ScrollViewWidth, height: scrollViewHeight))
imgOne.image = UIImage(named: "GoaLawah04.jpg")
imgOne.contentMode = UIViewContentMode.ScaleAspectFit
self.ScrollView.addSubview(imgOne)

let imgTwo = UIImageView(frame: CGRect(x: ScrollViewWidth, y: 0,width: ScrollViewWidth, height: scrollViewHeight))
imgTwo.image = UIImage(named: "GoaLawah07.jpg")
imgTwo.contentMode = UIViewContentMode.ScaleAspectFit
self.ScrollView.addSubview(imgTwo)

let imgThree = UIImageView(frame: CGRect(x: ScrollViewWidth*2, y: 0,width: ScrollViewWidth, height: scrollViewHeight))
imgThree.image = UIImage(named: "GoaLawah09.jpg")
imgThree.contentMode = UIViewContentMode.ScaleAspectFit
self.ScrollView.addSubview(imgThree)


self.ScrollView.contentSize = CGSize(width: ScrollViewWidth * 3, height: scrollViewHeight)
self.ScrollView.pagingEnabled = true

And yes note that your scrollview frame in storyboard or xib also. Because When your view contain scrollview then all subviews size automatically changes into weird frames when open old code in Xcode 8. So take care of it.

thank you for your return, I made the changes listed. at first it did not work I had the same problem. I canceled the constraints I had on the scroll View and it works. By against my scroll having no constraints, it takes more than the width of the screen.
Can you tell me why in add image3 * 2 behind ScrollViewWidth. if I add a fourth picture I will have to put * 3 ?? thank you again for your return and your useful info