Michael Long
1 min readMar 10, 2020

--

Getting automatic content sizing with UIScrollView using a content view and an “equal width” constraint is an old AutoLayout trick.

The classic approach prior to Xcode 11 was simply to set the width of the scroll view’s content view equal to the width of the scroll view’s parent view (typically the main view). Also easily done in Storyboard.

That constraint, along with the standard top, bottom, left and right constraints, told iOS you wanted automatic content sizing of the content viiew and — as long as all of your subviews were correctly pinned to the content view — iOS was happy to oblige.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

No responses yet