开发者

iphone: how to code different label for each image in scrollview

I successfully created a UIscrollview (horizontal) for 50 images and also created a label of "1 of 50" page number displaying at the top of the image along with the scroll view(for example user scroll to next image it would show 2 of 50, 3 of 50, so forth). I am able to display a label at the bottom of the image as a description.开发者_高级运维 My problem is how can I create or code to display different description for each image? Im thinking of NSarray but it shows some random numbers. Is there a sample I can look at to see what I am doing wrong. you can see the description part where I am lost from there. Thanks =)

    CGFloat xOffset = 0;
        NSInteger pageNumber = 1;
            NSUInteger i;
        for (i = 1; i <= 5; i++)
        {
            NSString *imageName = [NSString stringWithFormat:@"creative%d.jpg", i];
            UIImage *image = [UIImage imageNamed:imageName];
            UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

            [imageView setFrame:CGRectMake(xOffset, 0, 320, 288.5)];
            [ourScrollView addSubview:imageView];
            [imageView release];

            UILabel *pageNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(xOffset, -10, 320, 40)];
            [pageNumberLabel setText:[NSString stringWithFormat:@"%d of 5", pageNumber]];
            [pageNumberLabel setTextAlignment:UITextAlignmentLeft];
            [pageNumberLabel setTextColor:[UIColor whiteColor]];
                    [pageNumberLabel setBackgroundColor:[UIColor clearColor]];
                    [pageNumberLabel setFont:[UIFont fontWithName:@"MarkerFelt-Thin" size:18]];
            [ourScrollView addSubview:pageNumberLabel];
            [pageNumberLabel release];

  NSArray  *description = [NSArray arrayWithObjects:@"wow", @"bam", @"pow", @"zing", @"bling",nil];                 

                    UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(xOffset, 250, 320, 40)];
                    [descriptionLabel setText:[NSString stringWithFormat:@"%@", description]];
                            [descriptionLabel setTextAlignment:UITextAlignmentLeft];
            [descriptionLabel setTextColor:[UIColor whiteColor]];
                    [descriptionLabel setBackgroundColor:[UIColor clearColor]];
            [ourScrollView addSubview:descriptionLabel];
            [descriptionLabel release];

            xOffset = xOffset + 320;
            pageNumber = pageNumber + 1;


You're setting the descriptionLabel with a format of @"%d", which is a decimal format. What is "description"? If it's a NSString then you should be using @"%@".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜