Xcode 6 ScrollView with Universal Layout
With Xcode 6, w: Any and H: Any, I want to make a view that can be scrolled horizontally, there are 4 views in scrolling positioned horizontally and one is full width (see picture)
How can I achieve this with Xcode 6's new generic layout diagram?
I mean, I am confused about what constraints I have to use for each element to get it to work
+3
source to share
1 answer
As of Xcode 5, you need to make the content of the scroll more a multiple of the appearance of the scroll, and both scroll view and content view need to be restricted entirely.
To do this for different screen widths:
- Make a scroll view and constrain its borders.
- Add a UIView to the scroll view to limit the size of the scroll content, we will call this the content view.
- Add constraints to the appearance of the content so that the scrolling content is constrained by it.
- Make the content view equal to the width in the scroll view.
- Edit the equal width constraint so that the width of the content views is a multiple of the scroll width (a number that should be the number of pages).
- Add an appropriate height constraint to the content view (probably equal height with the scroll view).
Here is a sample project that does this. For a more detailed explanation there is a blog post here
+3
source to share