Reputation: 1899
I have a scroll view added to the View Controller's View. On iPhone XR, the scroll view subviews appear to the left because the scrollView does not expand its parent's view and is not centered. How can I make the scroll view take the full width and height of its parent's view and center it?
Upvotes: 0
Views: 176
Reputation: 1113
add below constraint to scrollview
scrollview.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(scrollview)
scrollview.topAnchor.constraint(equalTo: self.view.topAnchor, constant : 0).isActive = true
scrollview.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant : 0).isActive = true
scrollview.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant :0).isActive = true
scrollview.centerXAnchor.constraint(equalTo: self.view.centerXAnchor, constant: 0).isActive = true
scrollview.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0).isActive = true
Upvotes: 1