Paged UIScrollView with UIImageViews only showing first UIImageVIew

Posted by Jonathan Brown on Stack Overflow See other posts from Stack Overflow or by Jonathan Brown
Published on 2012-09-17T03:35:30Z Indexed on 2012/09/17 3:37 UTC
Read the original article Hit count: 122

Filed under:
|
|

I am working on a paged UIScrollView, but it only wants to show the first UIImageView within it. I add each UIImageView at an offset of the width of the scroll view, so that should create each page. When run, it says the scroll view is the right number of pages, but the images don't show.

Any help would be much appreciated!

int numSlides = NUM_TUTORIAL_SLIDES;
    NSString *fileName;
    UIImageView *slideImageView;
    CGRect slideFrame;

    for (int i = 1; i <= numSlides; i++)
    {
        slideFrame.origin.x = self.tutorialScrollView.frame.size.width * (i-1);
        slideFrame.origin.y = 0;
        slideFrame.size = self.tutorialScrollView.frame.size;

        slideImageView = [[UIImageView alloc] initWithFrame:slideFrame];


        if([[AppManager sharedManager] is4inchScreen])
        {
            fileName = [NSString stringWithFormat:@"Slide%[email protected]", i];
        }

        else
        {
            fileName = [NSString stringWithFormat:@"Slide%[email protected]", i];
        }

        slideImageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];

        [self.tutorialScrollView addSubview:slideImageView];

        [slideImageView release];
    }

    self.tutorialScrollView.contentSize = CGSizeMake(self.tutorialScrollView.frame.size.width * numSlides, self.tutorialScrollView.frame.size.height);

    self.tutorialScrollView.delegate = self;

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c