Guest User

Untitled

a guest
Jan 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. UIButton *galleryButton = [UIButton buttonWithType:UIButtonTypeCustom];
  2.  
  3. [galleryButton addTarget:self action:@selector(ScrollView:) forControlEvents:UIControlEventTouchUpInside];
  4.  
  5. galleryButton.frame = CGRectMake(0, 0, 30, 30);
  6.  
  7. UIImage *ime = [UIImage imageNamed:@"photos.png"];
  8.  
  9. [galleryButton setImage:ime forState:UIControlStateNormal];
  10.  
  11. UIBarButtonItem *gallerybutton = [[UIBarButtonItem alloc] initWithCustomView:galleryButton];
  12.  
  13. -(void)ScrollView:(id)sender
  14. {
  15. ImageScrollViewController *imagescrollviewcontroller = [[ImageScrollViewController alloc] init];
  16.  
  17. [self presentViewController:imagescrollviewcontroller animated:YES completion:NULL];
  18.  
  19. [imagescrollviewcontroller release];
  20.  
  21.  
  22. }
  23.  
  24. - (void)viewDidLoad
  25. {
  26.  
  27. self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
  28.  
  29. [_imageScrollView setBackgroundColor:[UIColor blackColor]];
  30. [_imageScrollView setCanCancelContentTouches:NO];
  31. _imageScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  32. _imageScrollView.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
  33. _imageScrollView.scrollEnabled = YES;
  34.  
  35. _imageScrollView.pagingEnabled = YES;
  36.  
  37.  
  38. // load all the images from our bundle and add them to the scroll view
  39. NSUInteger i;
  40. for (i = 1; i <= kNumImages; i++)
  41. {
  42. NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];
  43. UIImage *image = [UIImage imageNamed:imageName];
  44. UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  45.  
  46.  
  47. CGRect rect = imageView.frame;
  48. rect.size.height = kScrollObjHeight;
  49. rect.size.width = kScrollObjWidth;
  50. imageView.frame = rect;
  51. imageView.tag = i;
  52. [_imageScrollView addSubview:imageView];
  53. //[imageView release];
  54. }
  55.  
  56. [self layoutScrollImages];
  57.  
  58.  
  59. - (void)layoutScrollImages
  60. {
  61. UIImageView *view = nil;
  62. NSArray *subviews = [_imageScrollView subviews];
  63.  
  64. // reposition all image subviews in a horizontal serial fashion
  65. CGFloat curXLoc = 0;
  66. for (view in subviews)
  67. {
  68. if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
  69. {
  70. CGRect frame = view.frame;
  71. frame.origin = CGPointMake(curXLoc, 0);
  72. view.frame = frame;
  73.  
  74. curXLoc += (kScrollObjWidth);
  75. }
  76. }
  77.  
  78. // set the content size so it can be scrollable
  79. [_imageScrollView setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [_imageScrollView bounds].size.height)];
  80. }
Add Comment
Please, Sign In to add comment