Swift UI Special Training page control

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.