Skip to content

Instantly share code, notes, and snippets.

@Qiki
Created October 27, 2013 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qiki/7186792 to your computer and use it in GitHub Desktop.
Save Qiki/7186792 to your computer and use it in GitHub Desktop.
Showing various images in a scroll view
self.scrollView.pagingEnabled = YES; // making the image can scroll one by one
+ for(NSInteger i = 0; i < self.imageURL.count;i++){ //doing several loop to add the image on the scroll view
+
+ CGFloat xOrigin = i * self.view.frame.size.width;
+ UIImageView *awesomeView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height-90)];
+ [awesomeView setImageWithURL:self.imageURL[i][@"2x"]];
+ [self.scrollView addSubview:awesomeView];
+ }
+
+ [self.scrollView setContentOffset:CGPointMake([self.tag integerValue] * self.view.frame.size.width, 0) animated:NO];//set offset-- which means the first image show- basing on the width and do calculation
+ self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * self.imageURL.count, 1); //the overall scrollview size
+ [self.view addSubview:self.scrollView];//add the scroll view into the view.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment