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?
- Uipagecontrol * mypagecontrol = [[uipagecontrol alloc] initwithframe: cgrectmake (0.0, 400.0, 320.0, 0.0)];
Ii. Set attributes
1. Number of pages
[Java]
View plaincopyprint?
- 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?
- 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?
- 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?
- Mypagecontrol. deferscurrentpagedisplay = yes;
- [Mypagecontrol updatecurrentpagedisplay];
3. display controls
[Java]
View plaincopyprint?
- [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?
- -(Void) pagechanged :( ID) sender {
- Uipagecontrol * control = (uipagecontrol *) sender;
- Nsinteger page = control. currentpage;
- // Add the code you want to process
- }
- [Mypagecontrol addtarget: Self action: @ selector (pagechanged :) forcontrolevents: uicontroleventvaluechanged];