Search code examples
iosxcodeuiscrollviewinterface-builderscrollview

How Do I Create A Simple Scroll View That Scrolls Through Static Images?


Perhaps it's something with Xcode 4.5+ or iOS 6 that makes my research fruitless so far, but...

  • Apple's own advice hasn't worked for me. I set the contentSize to something different, and it causes no changes.
  • I found this wasn't unique to me, but the answer in that question 1.) does not inform me about the problem and 2.) I'm left wondering if it's really impossible to create a simple, non-inheriting example of UIScrollView. Thus, this question.
  • A better answer's code was tried within viewDidLoad and viewDidAppear, but to no avail.

So what gives? Is it possible to create a simple, image-filled view that allows scrolling? Say... something as easy as this basic project I set up on github -- but working?


Solution

    1. Create and initialize a UIScrollView
    2. Add it as subview to the view of viewcontroller
    3. Make an array of image names
    4. In a loop create UIImageView and add the images and add imageviews into scrollview considering the width of images, set the frame of imageviews
    5. Number of images is known and the width it consumes can be calulated from the loop itself use it to set the contentSize of the scrollview