How to use UIScrollView to show different images on scroll
<p>I am creating a small application using scroll view. I have loaded images into database which I want to display. I am able to display only the last image and the images are also not scrolling horizontally. Every image has a image name too which I want to display in the label as the image changes on scroll but I can't. </p>

<pre><code>//Code to display images in imageview placed on scrollview
-(void)imageDisplay
{
    //setup the scrollview for multiple images and add it to the view controller
    [scrollView setBackgroundColor:[UIColor blackColor]];
    [scrollView setCanCancelContentTouches:NO];
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;

    scrollView.clipsToBounds = YES;  //default is NO, we want to restrict drawing within our scrollview
    scrollView.scrollEnabled = YES;
    scrollView.pagingEnabled = YES;

    //load all images from database and add them to scroll view
    NSUInteger imageCount;
    int counter = 0;
    for(imageCount = 0; imageCount &lt; fetchedImageCount; imageCount++)
    {
        dictResults = [fetchedObjects objectAtIndex: imageCount];

        imgPath = [dictResults valueForKey:@"imageData"];
        NSLog(@"image path%@", imgPath);
        imgData = [NSData dataWithContentsOfFile: imgPath];
        image1 = [UIImage imageWithData:imgData];

        imageView = [[UIImageView alloc] initWithImage:image1];

        if(imageView == nil)
            break;

        CGRect rect = imageView.frame;
        rect.size.height =199.0;
        rect.size.width = 280.0;
        imageView.frame = rect;
        counter = counter + 1;
        imageView.tag = counter;

        lblImageTitle.text = [dictResults valueForKey:@"imageName"];
        [scrollView addSubview:imageView];
//        [imageView release];
    }
    [self layoutScrollImages];

}


//Code to assign imageview to scroll view and setup
-(void)layoutScrollImages
{
    UIImageView *view = nil;
    NSArray *subViews = [scrollView subviews];

    //reposition all image subviews in a horizontal serial fashion;
    CGFloat currentXLocation = 0;
    for(view in subViews)
    {
        NSLog(@"subview%d", [[scrollView subviews] count]);
        if([view isKindOfClass:[UIImageView class]] &amp;&amp; view.tag &gt; 0)
        {
            NSLog(@"view.tag %d", view.tag );
            CGRect frame = view.frame;
            frame.origin = CGPointMake(currentXLocation, 0);
            view.frame = frame;
            currentXLocation += 280.0;
        }
    }
    //set content size so it can be scrollable
    [scrollView setContentSize:CGSizeMake(fetchedImageCount*280.0, [scrollView bounds].size.height)];
}
</code></pre>

<p>Thanks in advance for your help</p>
