以下のコードを確認してください。ここでは、コードを使用してすべてを実行しました。それがあなたを助けることを願っています。
int numberOfPages = 5 ;
UIScrollView *scrollQuestionList = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height - 70.0)];
scrollQuestionList.contentSize = CGSizeMake(numberOfPages*scrollQuestionList.frame.size.width, scrollQuestionList.frame.size.height);
[self.view addSubview:scrollQuestionList];
scrollQuestionList.backgroundColor = [UIColor clearColor];
scrollQuestionList.delegate = self;
scrollQuestionList.showsHorizontalScrollIndicator = NO;
scrollQuestionList.pagingEnabled = YES;
CGFloat x = 0.0;
tagForBtns = 0;
for (int i = 1; i <= numberOfPages; i++)
{
UIView *contentView = [[[UIView alloc] initWithFrame:CGRectMake(x, 0.0, scrollQuestionList.frame.size.width, scrollQuestionList.frame.size.height)] autorelease];
if (i%2 == 0)
{
[contentView setBackgroundColor:[UIColor grayColor]];
}
else
{
[contentView setBackgroundColor:[UIColor cyanColor]];
}
[scrollQuestionList addSubview:contentView];
x+= scrollQuestionList.frame.size.width;
}
UIPageControl *pageCntrl = [[UIPageControl alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height - 70.0, self.view.frame.size.width, 25.0)];
pageCntrl.numberOfPages = numberOfPages;
pageCntrl.backgroundColor = [UIColor clearColor];
[pageCntrl addTarget:self action:@selector(clickedPageControl:) forControlEvents:UIControlEventValueChanged];
pageCntrl.currentPage = 0;
[self.view addSubview:pageCntrl];