How to create a paging scrollView with space between views

Posted by user1558819 on Stack Overflow See other posts from Stack Overflow or by user1558819
Published on 2012-09-11T01:23:52Z Indexed on 2012/09/11 3:38 UTC
Read the original article Hit count: 236

I followed the tutorial about how to create a scrollView Page Control: http://www.iosdevnotes.com/2011/03/uiscrollview-paging/

This tutorial is really good and I implement well the code. Here my question:

I want to put a space between the my PageViews, but when it change the page it show the space between the views in the next page. The scroll must stop after the space when I change the page.

Someone can help me?

I change the tutorial code here:

    - (void)viewDidLoad {
    [super viewDidLoad];

    NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];

     #define space 20

     for (int i = 0; i < colors.count; i++) {
      CGRect frame;
      frame.origin.x = (self.scrollView.frame.size.width + space) * i;
      frame.origin.y = 0;
      frame.size = self.scrollView.frame.size;

      UIView *subview = [[UIView alloc] initWithFrame:frame];
      subview.backgroundColor = [colors objectAtIndex:i];
      [self.scrollView addSubview:subview];
      [subview release];
     }

    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count+ space*(colors.count-1), self.scrollView.frame.size.height);
    }

Thanks,

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c