title: iOS : How to do proper paging in UIScrollView?
body: <p>I've a <code>UIScrollView</code> of size (320,160). I'm adding some <code>UIImageView</code> into it, which are of size (213,160). The first <code>UImageView</code> starting from 54 (x) and so on, I've added a space of 5.0 in between each <code>UIImageView</code>. I've also enabled <code>pagingEnable</code> in <code>IB</code> &amp; in <code>coding</code>. What my problem is its not properly working as per its property! When I scroll it should show me <code>UIImageViews</code> in each single <code>page</code> instead it showing me something like <a href="https://i.stack.imgur.com/pOn6Q.png" rel="nofollow noreferrer">see screenshot</a> I want output something like this <a href="https://i.stack.imgur.com/CHWNG.png" rel="nofollow noreferrer">see output screenshot</a></p>
  
  <p>Where I'm doing wrong? I also having function of<code>&lt;</code> (previous) &amp; <code>&gt;</code> (next) there to show images. I've asked one question yesterday which was I accepted however my requirement is little change and it won't become my solution. <a href="https://stackoverflow.com/q/12722254/1603234">see my question.</a></p>
  
  <p>Is there any special property that I've to set, or some logic I should implement? All examples I've checked and tried but I find that my requirement is some special. Point me! Thanks.</p>
  
  <p><strong>EDITED:</strong></p>
  
  <pre><code>- (void) setImages
  {
  CGFloat contentOffset = 0.0f;
  
      for (int i=0; i&lt;[arrImgUrls count]; i++) 
      {
          CGRect imageViewFrame = CGRectMake(contentOffset, 0.0f, 213, scrollImages.frame.size.height);
          AsyncImageView *asyncImageView = [[AsyncImageView alloc] initWithFrame:imageViewFrame];
          [asyncImageView.layer setMasksToBounds:YES];
          NSString *urlImage = [arrImgUrls objectAtIndex:i];
          NSURL *url = [NSURL URLWithString:urlImage];
          [asyncImageView loadImageFromURL:url];
          [scrollImages addSubview:asyncImageView];
      contentOffset += asyncImageView.frame.size.width+increment;
          [asyncImageView release];
  }
  
      scrollImages.contentSize = CGSizeMake([arrImgUrls count] * scrollImages.frame.size.width, scrollImages.frame.size.height);
      scrollImages.pagingEnabled = YES;
      scrollImages.clipsToBounds = NO;
  }
  
  -(IBAction)prevImage:(id)sender
  {    
       _currentImage--;
  
       [btnNext setEnabled:YES];
  
       if (_currentImage==0)
       {
           [btnPrev setEnabled:NO];
           [scrollImages setContentOffset:CGPointMake((_currentImage*imageWidth), 0) animated:YES];
           return;
       }
  
       NSLog(@"previous:mult %d inc %d current %d",_currentImage*imageWidth,increment*_currentImage,_currentImage);
  
       int nextImage=_currentImage+2;
  
       [scrollImages setContentOffset:CGPointMake((((_currentImage*imageWidth)-(increment*_currentImage)))+(nextImage*increment), 0) animated:YES];
   }
  
  -(IBAction)nextImage:(id)sender
  {    
     _currentImage++;
  
     NSLog(@"next:mult %d inc %d current %d",_currentImage*imageWidth,increment*_currentImage,_currentImage);
  
    [scrollImages setContentOffset:CGPointMake((_currentImage*imageWidth)+(increment*_currentImage), 0) animated:YES];
  
    [btnPrev setEnabled:YES];
  
    if (_imageCount-1 == _currentImage)
   {
      [btnNext setEnabled:NO];
   }
  }
  </code></pre>