如何将图像添加到UIPageViewController?

时间:2013-10-09 07:13:03

标签: iphone ios objective-c uipageviewcontroller

我有一个UIPageViewController,有5个屏幕。请参见下图

enter image description here

我需要添加一些图片而不是标签屏幕#1 屏幕#2 等。

Here is my code

有人可以告诉我解决方案吗?

1 个答案:

答案 0 :(得分: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];