Sometimes our page is very large need to scroll only with scroll bar scrolling can be less precise, this need to use page Control, as we usually operate the iphone, each page has some apps, the number of pages is marked with small dots, each time a swipe will switch the page, The dots of the currently paused page are lit. For example, we usually use the weather forecast, each page can only show the weather of one place, each change page can switch to other cities. The properties of Page control are not many, as follows:
The two numbers in pages are labeled with a few pages, which page is currently on.
Behavior flag is currently only one page can be hidden, the rest is the color of the settings.
OK, let's define it, now the display effect
To achieve scrolling, with ScrollView, so to implement the ScrollView agent. Add a simple view to the page:
To make it obvious, change the background color to gray, and now the page looks like this:
Associating the view with the controller, when we select Page control and then open its event manager, we see a lot of events, select the Vale changed, and associate with the controller.
We have five pages, in order to show the difference, give them different colors. Create a color array:
let color = [ uicolor.blackcolor (), Uicolor.bluecolor (), Uicolor.browncolor (), Uicolor.orangecolor (), Uicolor.purplecolor () ]
To add an action to the event we just added:
@IBAction func Pagechange (sender:uipagecontrol) { Colorview.backgroundcolor = color[sender.currentpage] }
Can be run to look at:
Swift UI Special Training page control