答案 0 :(得分:0)
尝试使用启用了分页的UIScrollView。然后将IBAction连接到带有标记值的按钮。标记值指示UIScrollView必须显示的页面。确保UIScrollView方向设置为水平。在这个例子中,我只是添加了UIViews,但这可能是任何东西。您可以使用UITableView,UIScrollView或UICollectionView命名。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//Set number of pages
int numberOfPages = 3;
//Set properties scrollView
self.scrollView.pagingEnabled = true;
self.scrollView.contentSize = CGSizeMake((numberOfPages * self.scrollView.frame.size.width), self.scrollView.frame.size.height);
//Add pages
UIView *pageOne = [[UIView alloc] initWithFrame:CGRectMake((0 * self.scrollView.frame.size.width), 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
[pageOne setBackgroundColor:[UIColor yellowColor]];
[self.scrollView addSubview:pageOne];
UIView *pageTwo = [[UIView alloc] initWithFrame:CGRectMake((1 * self.scrollView.frame.size.width), 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
[pageTwo setBackgroundColor:[UIColor blueColor]];
[self.scrollView addSubview:pageTwo];
UIView *pageThree = [[UIView alloc] initWithFrame:CGRectMake((2 * self.scrollView.frame.size.width), 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height)];
[pageThree setBackgroundColor:[UIColor redColor]];
[self.scrollView addSubview:pageThree];
}
- (IBAction)btnSelectPage:(id)sender; {
UIButton *btn = (UIButton *)sender;
[self.scrollView setContentOffset:CGPointMake((self.scrollView.frame.size.width * btn.tag), 0) animated:true];
}