Reputation: 1
for the past couple weeks I have been stuck on getting A UIIMageView to work correctly with a UIScrollView. My image is 320x9100 and all I am trying to do is get it to scroll vertically. Everything was going great until I added [email protected] to use for retina display, but since the lengths of the images are different the scrollview ends before the image does. What is the best way to do this? Any help would be greatly appreciated!
P.S. I would be even more grateful if I could just email you the project and you could fix it for me :)
Thanks in advance!!!
Upvotes: 0
Views: 270
Reputation: 1476
Xcode handles the retina images automatically.
[scrollView setContentSize:imageView.frame.size];
This will work if you're setting the image programmatically or in the xib file.
Here is some code to help explain it. It assumes you have a UIScrollView in your .xib file connected to an IBOutlet called scrollview in your .h file.
// Init the image
UIImage *image = [UIImage imageNamed:@"myImage.png"];
// Init the image view
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// Position the image view
imageView.frame = CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height);
// Add the image view to your scroll view
[scrollView addSubview:imageView];
// Set the scroll view content size to match the image view size
[scrollView setContentSize:imageView.frame.size];
Upvotes: 1