Skip to content

Instantly share code, notes, and snippets.

@MaxGabriel
Created February 27, 2012 20:19
Show Gist options
  • Save MaxGabriel/1926754 to your computer and use it in GitHub Desktop.
Save MaxGabriel/1926754 to your computer and use it in GitHub Desktop.
Set photo for UIScrollView
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = _photoName;
_imageView.image = _image;
_imageView.frame = (CGRect){CGPointZero, _imageView.image.size};
_scroller.contentSize = _imageView.image.size;
_scroller.minimumZoomScale = .3;
_scroller.maximumZoomScale = 3;
_scroller.delegate = self;
_scroller.scrollEnabled = YES;
[_scroller setBackgroundColor:[UIColor blackColor]];
[_scroller addSubview:_imageView];
CGFloat width = _imageView.image.size.width;
CGFloat height = _imageView.image.size.height;
CGRect rect;
if (width > height) {
rect = CGRectMake(0, 0, 1, height+150);
} else {
rect = CGRectMake(0, 0, width, 1);
}
[_scroller zoomToRect:rect animated:NO];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment