简体   繁体   English

如何使用Xcode 4.2和故事板使用“页面控制”?

[英]How to use a “Page Control” using Xcode 4.2 and storyboard?

I'm trying to learn the basics of iOS programming and I was wondering how you would use a page control using Xcode 4.2 and storyboard? 我正在尝试学习iOS编程的基础知识,我想知道如何使用Xcode 4.2和故事板进行页面控制? I'm subscribed to MyCodeTeacher.com and the lesson on Page Controllers is outdated and doesn't work with the new Xcode. 我订阅了MyCodeTeacher.com,页面控制器上的课程已经过时,并且不适用于新的Xcode。 I cant find a tutorial via Google and the Apple Documentation isn't helping either. 我无法通过谷歌找到一个教程,Apple文档也没有帮助。 Can someone point me to a good tutorial or give me a basic example? 有人能指点我一个好的教程或给我一个基本的例子吗?

Thank you SO much! 非常感谢!

Ok here is a workflow for a typical case: 好的,这是一个典型案例的工作流程:

1.Create an IBOutlet for your pageControl object 1.为pageControl对象创建一个IBOutlet

Example: 例:

@property (unsafe_unretained, nonatomic) IBOutlet UIPageControl *pageControl;

2.Create an IBAction as well for the "Value Changed" event of the same pageControl 2.为同一pageControl的“Value Changed”事件创建IBAction

Example: 例:

-(IBAction)pageDidChange:(id)sender;

Every time the user changes the page now, your pageDidChange: method will be fired. 每次用户现在更改页面时,都会触发pageDidChange:方法。

Now, here are some common methods: 现在,这里有一些常用的方法:

  1. Setup the number of pages 设置页数

    [self.pageControl setNumberOfPages:6];

  2. Set the current page 设置当前页面

    [self.pageControl setCurrentPage:1];

I hope that this will get you started... 我希望这能让你开始......

for adding view to each page use scrollview along with page control 为每个页面添加视图使用scrollview和页面控件

- (IBAction)changePage {

CGRect frame;

    frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;

 frame.origin.y = 0;

frame.size = self.scrollView.frame.size;

 [self.scrollView scrollRectToVisible:frame animated:YES];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM