通过数组进行页面控制
我有兴趣使用页面控件来切换数组中的条目而不更改视图。我该怎么做?有教程吗。 。 。
然而,每当页面切换时,背景颜色和一些图像就会改变。有没有办法在页面切换后运行代码?
谢谢
I am interested in using a page control to switch through entries in my array without changing the view. How can I do this? Is there a tutorial. . .
However, whenever the pages is switched, the background color and some images change. Is there any way to run code once a page is switched?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIPageControl
仅代表分页,它本身不管理分页行为。单击UIPageControl
时,您需要编写自己的代码来迭代数组。currentPage
属性应设置为您在数组中使用的索引,totalPages
属性应设置为数组的count
属性。最后,您需要使用-addTarget:action:forControlEvents:
文档状态:
因此,您可以使用该事件来确定页面何时更改。
示例:
[...]
当您单击页面控件时,它会在
self.items
属性表示的字符串数组中向前或向后移动。-pageChanged:
也是您更新视图上的控件的位置。如果你想更新另一个区域的 UIPageControl 中的当前页面,只需执行以下操作:
UIPageControl
only represents paging, it does not manage the paging behavior itself. You will need to write your own code to iterate through your array when clicking on theUIPageControl
. ThecurrentPage
property should be set to the index you are working with in your array, thetotalPages
property should be set to the array'scount
property. Finally, you'll need to setup a target/action pair for theUIControlEventValueChanged
event using-addTarget:action:forControlEvents:
The documentation states:
So you can use that event to determine when a page is changed.
Example:
[...]
When you click the page control, it moves forward or backward through the array of strings represented by the
self.items
property.-pageChanged:
is where you would update the controls on the view as well.If you want to update the current page in the UIPageControl in another area, simply do: