Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 is 4 view in the scrollview placed horizontally, and one is take full width, (see picture)

How to achieve this with Xcode 6 new universal layout paradigm?

i mean, i am confused with what constraints i should use for each element to make it work

enter image description here

like image 665
DeckyFx Avatar asked Jul 15 '26 15:07

DeckyFx


1 Answers

As in Xcode 5 you need to make the contents of the scroll view a multiple of the outside of the scroll view, and both the scroll view and content view need there bounds to be fully constrained.

To do this for different width screens:

  • Make the scroll view and constrain its bounds.
  • Add a UIView into the scroll view to constrain the contents size of the Scroll view, we'll call it a content view.
  • Add constraints to the outside of the content view so that the contents of the scroll view is bounded by it.
  • Make the content view equal widths to the scroll view.
  • Edit the equal widths constraint so the content views width is a multiple of the scroll views widths (the multiple needs to be the number of pages)
  • Add relevant height constraint to the content view (probably equal height with the scroll view).

Here's a sample project that does this. For a more detailed explanation there is a blog post here

like image 179
James Snook Avatar answered Jul 19 '26 04:07

James Snook



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!