I’ve found some other answers here, but they don’t seem to apply/work, so I figure it might be due to my particular code.
In my app, I have an array of UIImages, which are actually scaled down photos taken by the iPhone camera.
I am attempting to show the UIImage within a scrollView, correctly scaled to show the entire image.
This is my code:
scrollView.pagingEnabled = YES;
scrollView.clipsToBounds = NO;
CGFloat contentOffset = 0.0f;
pageControl.numberOfPages = [imageArray count];
pageControl.currentPage = 0;
for(UIImage *image in imageArray)
{
NSLog(@"image width = %f, image height = %f", image.size.width, image.size.height);
CGRect imageViewFrame = CGRectMake(contentOffset, 0, scrollView.frame.size.width, scrollView.frame.size.height);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageViewFrame];
[imageView setImage:image];
[imageView setClipsToBounds:YES];
[imageView setContentMode:UIViewContentModeScaleAspectFill]; //I've tried others, but nothing seems to show the entire image
[scrollView addSubview:imageView];
[imageView release];
contentOffset += scrollView.frame.size.width;
[scrollView setContentSize:CGSizeMake(contentOffset, 0)];
}
Just to note, this is a portrait-oriented app and the image itself was taken in portrait orientation.
The NSLog output:
image width = 387.200012, image height = 518.400024
The image that I see show up on the UIImageView (within the scrollview) is a zoomed up image of the center of the image, no matter what I change the contentmode to.
What am I doing wrong here? thank you!
The answer is what I had commented earlier: the scaling factor of the UIImage caused the ContentMode not to work. Or at least, made it seem not to work.