目前,我正在开发一个使用滚动视图的移动应用程序。在该滚动视图中有页面。我需要显示8页。但是现在,移动应用程序中只显示了5个页面。我不知道错误发生在哪里。有人可以帮帮我吗?
下面是我的代码。
self.MainScrollview.delegate = self;
[self.view addSubview:self.MainScrollview];
CGSize scrollViewContentSize = CGSizeMake(self.MainScrollview.frame.size.width*5, 380);
[self.MainScrollview setContentSize:scrollViewContentSize];
[self.MainScrollview setPagingEnabled:YES];
self.MainScrollview.showsHorizontalScrollIndicator = NO;
self.MainScrollview.backgroundColor = [UIColor clearColor];
//[self.view addSubview:self.MainScrollview];
self.pageControl = [[UIPageControl alloc] init];
self.pageControl.frame = CGRectMake(0,440,320,20);
if (iOSDeviceScreenSize.height == 568){
self.pageControl.frame = CGRectMake(0,440+50,320,20);
}else{
if (versionCheck >= 7)
self.pageControl.frame = CGRectMake(0,440+20,320,20);
}
self.pageControl.numberOfPages = 8;
self.pageControl.currentPage = self.productNum;
self.pageControl.backgroundColor = [UIColor clearColor];
self.pageControl.enabled = NO;
//self.pageControl.pageIndicatorTintColor = [UIColor colorWithRed:0/255.0 green:73/255.0 blue:144/255.0 alpha:1.0];
[self.view addSubview:self.pageControl];
// Product 1
UIScrollView* scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
scrollview.contentSize = CGSizeMake(290, 380);
scrollview.backgroundColor = [UIColor clearColor];
scrollview.zoomScale = 1.0;
[self.MainScrollview addSubview:scrollview];
UIImage *i1 = [UIImage imageNamed:@"roundedbox3.png"];
UIImageView *iv1 = [[UIImageView alloc] initWithImage:i1];
iv1.frame = CGRectMake(10, 10, 601/2, 755/2);
[scrollview addSubview:iv1];
UIImage *producUp = [UIImage imageNamed:@"Enfamama-A+.png"];
UIImageView *producUpV = [[UIImageView alloc] initWithImage:producUp];
producUpV.contentMode = UIViewContentModeScaleAspectFit;
producUpV.frame = CGRectMake(10 , 0, 600/2, 978/2);
[scrollview addSubview:[self addImageToScrollView:producUpV]];
UIButton *moreInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[moreInfoBtn setBackgroundImage:[UIImage imageNamed:@"moreInfoProd.png"] forState:UIControlStateNormal];
moreInfoBtn.frame = CGRectMake(15+70, 343, 264/2, 87/2);
[moreInfoBtn addTarget:self action:@selector(getMoreInfo) forControlEvents:UIControlEventTouchUpInside];
[scrollview addSubview:moreInfoBtn];
UIButton *sampleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[sampleBtn setBackgroundImage:[UIImage imageNamed:@"freesampleProd.png"] forState:UIControlStateNormal];
sampleBtn.frame = CGRectMake(320-25-129, 345, 258/2, 87/2);
[sampleBtn addTarget:self action:@selector(getSample) forControlEvents:UIControlEventTouchUpInside];
//[scrollview addSubview:sampleBtn];
答案 0 :(得分:0)
如果您期望8页,则不应该从此
更改代码的第三行CGSize scrollViewContentSize = CGSizeMake(self.MainScrollview.frame.size.width*5, 380);
到这个
CGSize scrollViewContentSize = CGSizeMake(self.MainScrollview.frame.size.width*8, 380);
意味着您需要将宽度从5
增加到8
次