I have a UIScrollView with paging enabled. I want to full it with images and I have a UIImageView which needs to be made to fit without using .frame. This is because it doesn’t work with Autolayout enabled. Not using Autolayout isn’t an option.
Here’s the code as it stands:
//Prepare and load the view
[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), (kScrollObjHeight))];
scrollView1.pagingEnabled = YES;
[scrollView1 setShowsHorizontalScrollIndicator:NO];
CGRect Rect = scrollView1.bounds;
UIImageView *beadContainer;
for (int i = 0; i < imageViews.count; i++)
{
beadContainer = [imageViews objectAtIndex:i];
beadContainer.frame = Rect;
[scrollView1 addSubview:beadContainer];
Rect.origin.x += Rect.size.width;
}
None of the images appear as it stands, though the ScrollView has all of the right dimensions and scrolls as expected. If I comment out beadContainer.frame = Rect;, then all of the images in the array imageViews appear at 0, 0. They all show up on top of one another. Of course, I need them to fill the ScrollView.
Why don’t you use autolayout to layout the images?
Mind you I haven’t tried this, it might be rubbish code, I wrote it in a text editor.