Images in a Scroll View


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #define IMAGE_WIDTH 320
  2. #define IMAGE_HEIGHT 416
  3.  
  4. - (void)viewDidLoad
  5. {
  6. [super viewDidLoad];
  7.  
  8. NSArray *photos = nil; // TODO – fill with your photos
  9.  
  10. // note that the view contains a UIScrollView in aScrollView
  11.  
  12. int i=0;
  13. for ( NSString *image in photos )
  14. {
  15. UIImage *image = [UIImage imageNamed:[photos objectAtIndex:i]];
  16. UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  17. imageView.contentMode = UIViewContentModeScaleAspectFit;
  18. imageView.clipsToBounds = YES;
  19.  
  20. imageView.frame = CGRectMake( IMAGE_WIDTH * i++, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
  21.  
  22. [aScrollView addSubview:imageView];
  23. [imageView release];
  24. }
  25. aScrollView.contentSize = CGSizeMake(IMAGE_WIDTH*i, IMAGE_HEIGHT);
  26. aScrollView.delegate = self;
  27. }

URL: http://www.chewyapps.com/2009/09/01/images-in-a-scroll-view/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.