Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UIButton *galleryButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [galleryButton addTarget:self action:@selector(ScrollView:) forControlEvents:UIControlEventTouchUpInside];
- galleryButton.frame = CGRectMake(0, 0, 30, 30);
- UIImage *ime = [UIImage imageNamed:@"photos.png"];
- [galleryButton setImage:ime forState:UIControlStateNormal];
- UIBarButtonItem *gallerybutton = [[UIBarButtonItem alloc] initWithCustomView:galleryButton];
- -(void)ScrollView:(id)sender
- {
- ImageScrollViewController *imagescrollviewcontroller = [[ImageScrollViewController alloc] init];
- [self presentViewController:imagescrollviewcontroller animated:YES completion:NULL];
- [imagescrollviewcontroller release];
- }
- - (void)viewDidLoad
- {
- self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
- [_imageScrollView setBackgroundColor:[UIColor blackColor]];
- [_imageScrollView setCanCancelContentTouches:NO];
- _imageScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
- _imageScrollView.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
- _imageScrollView.scrollEnabled = YES;
- _imageScrollView.pagingEnabled = YES;
- // load all the images from our bundle and add them to the scroll view
- NSUInteger i;
- for (i = 1; i <= kNumImages; i++)
- {
- NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
- UIImage *image = [UIImage imageNamed:imageName];
- UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
- CGRect rect = imageView.frame;
- rect.size.height = kScrollObjHeight;
- rect.size.width = kScrollObjWidth;
- imageView.frame = rect;
- imageView.tag = i;
- [_imageScrollView addSubview:imageView];
- //[imageView release];
- }
- [self layoutScrollImages];
- - (void)layoutScrollImages
- {
- UIImageView *view = nil;
- NSArray *subviews = [_imageScrollView subviews];
- // reposition all image subviews in a horizontal serial fashion
- CGFloat curXLoc = 0;
- for (view in subviews)
- {
- if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
- {
- CGRect frame = view.frame;
- frame.origin = CGPointMake(curXLoc, 0);
- view.frame = frame;
- curXLoc += (kScrollObjWidth);
- }
- }
- // set the content size so it can be scrollable
- [_imageScrollView setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [_imageScrollView bounds].size.height)];
- }
Add Comment
Please, Sign In to add comment