how do I dynamically adjust the size of an image to fit UIScrollView?

I have three UIScrollViews in my app. These UIScrollViews are placed at the top of the screen, in the middle of the screen, and at the bottom of the screen. These UIScrollViews automatically adjust from within Interface Builder and Auto Layout. I think I am setting the scrollview content size to adjust based on the device used with;


< scrollView.contentSize = CGSizeMake(2990, self->scrollView.frame.size.height); >


but when I add an image;


< UIImage *image = [UIImage imageNamed:@"Top View Strip 5.png"];

UIImageView *imageView = [[UIImageView alloc] initWithImage: image];

[scrollView addSubview:imageView];

[self.view addSubview:scrollView]; >


the image size does not adjust to fill the scrollView. Perhaps I am not actually setting the scrollview content correctly?

So you want these images to fill the scroll view vertically, and scroll horizontally? In that case, compute the vertical scale factor (the image height divided by the scroll view height). The resize the UIImageView with its width set to the image width multiplied by the scale factor, and its height set to the scroll view height.


If you've actually placed the scroll views in Interface Builder as you said, you should not re-add the scroll view as a child of the parent view (your last line of code). It already is.

You may want to add the following:


imageView.frame=CGRectMake(0,0,scrollView.frame.size.width,scrollView.frame.size.height);
//and:
scrollView.delegate=self;
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return theBoardImageView;
}
how do I dynamically adjust the size of an image to fit UIScrollView?
 
 
Q