redribben

UIScrollView setup

Nov 3rd, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CalendarViewController.h
  2. ------------------------
  3. #import "ViewController.h"
  4. #import <UIKit/UIKit.h>
  5.  
  6. @interface CalendarViewController : ViewController<UIScrollViewDelegate> {
  7.     UIScrollView *myScrollView;
  8. }
  9. - (IBAction)backButton:(id)sender;
  10.  
  11. @property (nonatomic) IBOutlet UIImageView *scheduleImage;
  12.  
  13. @end
  14.  
  15.  
  16.  
  17. ------------------------
  18. ------------------------
  19. CalendarViewController.m File
  20. ------------------------
  21. @property (copy, nonatomic) UIImage *image;
  22.  
  23. @synthesize scheduleImage;
  24. - (void)viewDidLoad {
  25.     [super viewDidLoad];
  26.     [self displayImage];
  27.     [self addScrollView];
  28.  
  29. - (void)displayImage {
  30.     NSString *imagePath;
  31.     NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  32.     NSString *documentDirectoryPath = dirPaths[0];
  33.     NSString *calendarDir = [documentDirectoryPath stringByAppendingString:[NSString stringWithFormat:@"/CalendarFolder/"]];
  34.     NSArray *list = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:calendarDir error:nil];
  35.     for (NSString* file in list) {
  36.         if ([[file pathExtension] isEqualToString: @"png"]) {
  37. //            [[NSFileManager defaultManager] copyItemAtPath:file toPath:calendarDir error:nil];
  38.             imagePath = [calendarDir stringByAppendingPathComponent:file];
  39.         }
  40.     }
  41.     UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath];
  42.    
  43.     [self.scheduleImage setImage:image];
  44. }
  45.  
  46. -(void)addScrollView{
  47.     myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, [ [ UIScreen mainScreen ] bounds ].size.width, [ [ UIScreen mainScreen ] bounds ].size.height)];
  48.     myScrollView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"grey.png"]];
  49.  
  50.     myScrollView.accessibilityActivationPoint = CGPointMake(100, 100);
  51.    
  52.    
  53.    
  54. //    scheduleImage = [[UIImageView alloc]initWithImage:_image];
  55.     [myScrollView addSubview:scheduleImage];
  56.  
  57.     myScrollView.minimumZoomScale = 0.5;
  58.     myScrollView.maximumZoomScale = 3;
  59.     myScrollView.contentSize = CGSizeMake(scheduleImage.frame.size.width,
  60.                                           scheduleImage.frame.size.height);
  61.     myScrollView.delegate = self;
  62.     [self.view addSubview:myScrollView];
  63. }
Advertisement
Add Comment
Please, Sign In to add comment