Uipagecontrol paging control-iOS development

Source: Internet
Author: User

The pagination control is a visible indicator used to replace the navigation bar, allowing you to directly flip pages with gestures. The most typical application is the iPhone's main screen. When there are too many icons, the page is automatically added, at the bottom of the screen, you will see the origin point, which is used only for the current page and will be automatically updated with the page turning.

I. Create

[Java]
View plaincopyprint?
  1. Uipagecontrol * mypagecontrol = [[uipagecontrol alloc] initwithframe: cgrectmake (0.0, 400.0, 320.0, 0.0)];

Ii. Set attributes

1. Number of pages

[Java]
View plaincopyprint?
  1. Mypagecontrol. numberofpages = 5;

The first page is selected by default. If you want to select another page, you can set the currentpage attribute. The page index starts from 0:

[Java]
View plaincopyprint?
  1. Mypagecontrol. currentpage = 3; // current page number, fourth page

By default, the indicator is displayed even if there is only one page. To hide the indicator when there is only one page, you can set hideforsinglepage to yes.

[Java]
View plaincopyprint?
  1. Mypagecontrol. hidesforsinglepage = yes;

You can set deferscurrentpagedisplay to yes if you want to update the current indicator page until you have completed your operation. In this case, you must call the updatecurentpagedisplay control to update the current page:

[Java]
View plaincopyprint?
  1. Mypagecontrol. deferscurrentpagedisplay = yes;
  2. [Mypagecontrol updatecurrentpagedisplay];

3. display controls

[Java]
View plaincopyprint?
  1. [Self. View addsubview: mypagecontrol];

Iv. Notifications
When you click the page control, a uicontroleventvakuechanged event is generated. You can use the addtarget method of the uicontrol class to specify an action for it:

[Java]
View plaincopyprint?
  1. -(Void) pagechanged :( ID) sender {
  2. Uipagecontrol * control = (uipagecontrol *) sender;
  3. Nsinteger page = control. currentpage;
  4. // Add the code you want to process
  5. }
  6. [Mypagecontrol addtarget: Self action: @ selector (pagechanged :) forcontrolevents: uicontroleventvaluechanged];

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.