0

我有UIPageViewController5 个屏幕。请看下图

在此处输入图像描述

我需要添加一些图像而不是标签Screen #1Screen #2等。

这是我的代码

谁能告诉我解决方案?

4

1 回答 1

0

试试这个代码..

在 imageArray 数组中添加任何图像;

NSArray *imageArray=[[NSArray alloc]initWithObjects:@"SpaceTheme.png",@"BeachTheme.png",@"vintage.png", nil];

ScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320,480)];
[Scroll setPagingEnabled:YES];
[Scroll setShowsHorizontalScrollIndicator:NO];

for(n=0; n< [imageArray count];n++)
   {

    NSString *imageName=[imageArray objectAtIndex:n];

        NSString *fullImageName=[NSString stringWithFormat:@"%@",imageName];
        CGRect imageViewFrame;



            int padding=20;
            imageViewFrame=CGRectMake(Scroll.frame.size.width*n+padding-10,Scroll.frame.origin.y-130,Scroll.frame.size.width-1*padding, Scroll.frame.size.height);


        UIImageView *imageView=[[UIImageView alloc]initWithFrame:imageViewFrame];

        [imageView setImage:[UIImage imageNamed:fullImageName]];

        [imageView setContentMode:UIViewContentModeScaleAspectFit];

        [Scroll addSubview:imageView];

        pagecontrol.numberOfPages = 3;   // Give numbre of pages here 
        pagecontrol.currentPage = 0;

        [self.view addSubview:pagecontrol]; 
    }
    Scroll.delegate=(id)self;
    CGSize scrollViewSize=CGSizeMake(Scroll.frame.size.width*[imageArray count], Scroll.frame.size.height);
    [Scroll setContentSize:scrollViewSize];
    [self.view addSubview:Scroll];
于 2013-10-09T07:18:46.947 回答