My scrollView shows images downloaded from a server. Now i want to show additional information in an UILabel. However this is only shown under the first image. When scrolling the UILabel is not shown :-(
(void)populateImageArray:(NSNotification *)notif
{
NSUInteger i;
CGFloat contentOffset = 0.0f;
for (i = 0; i <= [items count]-1; i++)
{
CGRect imageViewFrame = CGRectMake(contentOffset, 0.0f, scrollViewPreview.frame.size.width, scrollViewPreview.frame.size.height);
// CGRect rect = CGRectMake(139 , 405, 120.0f, 45.0f);
CGRect rect = CGRectMake(0 , 330, 120.0f, 45.0f);
NSString *titleString, *preisString, *resultString;
titleString = [[items objectAtIndex:i] title];
preisString = [[items objectAtIndex:i] price];
resultString = @"";
resultString = [resultString stringByAppendingString:titleString];
resultString = [resultString stringByAppendingString:@"\n"];
resultString = [resultString stringByAppendingString:preisString];
UILabel *text = [[UILabel alloc] initWithFrame:rect];
[text setTextColor:[UIColor redColor]];
[text setNumberOfLines:0];
text.textAlignment=UITextAlignmentCenter;
[scrollViewPreview addSubview:text];
text.text = [NSString stringWithFormat:@"%d",resultString];
NSURL *urlString = [NSURL URLWithString:[[items objectAtIndex:i] bilder]];
NSData *data = [NSData dataWithContentsOfURL:urlString];
UIImage *image = [[UIImage alloc] initWithData:data];
//UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageViewFrame];
[imageView setImage:image];
//imageView.contentMode = UIViewContentModeCenter;
imageView.contentMode = UIViewContentModeScaleAspectFit;
[scrollViewPreview addSubview:imageView];
[text release];
[imageView release];
[titleString release];
[preisString release];
//[resultString release];
contentOffset += imageView.frame.size.width;
scrollViewPreview.contentSize = CGSizeMake(contentOffset, scrollViewPreview.frame.size.height);
}
scrollViewPreview.clipsToBounds = NO;
scrollViewPreview.pagingEnabled = YES;
scrollViewPreview.showsHorizontalScrollIndicator = YES;