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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.