答案 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];