Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Introduction to Scroll Views with Swift 2 Paged Scrolling Adding a Page Control

Pawel Zgoda-Ferchmin
Pawel Zgoda-Ferchmin
900 Points

How does the app know what I want a single page to be?

Is each page just the width of the screen?

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello:

If you notice he has a totalWidth in the for-in loop, which every time a page is loaded it "adds" to that property. So when the next page is loaded, then it's frame will be created with the value from totalWidth.

pageView.frame = CGRect(origin: CGPoint(x: totalWidth, y: 0), size: scrollView.bounds.size)

So, when the for in loop creates the first view, it's frame will be at 0,0 and then it will add the width to the property, let's say in this case it add's 10 points.

Then the next time the loop creates another view, this time it's frame will be at 10,0. Which means that it will create that page, 10 points to the right.

Hope you understand. If you want a more detailed explanation please let me know.

Good luck