PageControl Example In iPhone

A Page control presents the user with a set of horizontal dots representing pages. The current page is presented as a white dot. The user can go from the current page to the next or to the previous page.

Step 1: Create a Window-base application using template. Give the name of the application PageControlExample.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: We will create  UIScrollView for the scrollView,UIPageControl for the pageControl and also declear viewControllers. So we have to declear in the PageControlExampleAppDelegate.h file. Make the following changes in the header file.




Step 4: Open the MainWindow.xib file in the Interface Builder. First, drag scroll View from the library and place it to the window. Connect File’s Owner icon to the UIScrollView and select ScrollView. Drag Page Control from the library and place below of the UIScrollView. Now connect File’s Owner to the Page Controll and select Page Control. Save your .xib file and go back to the Xcode.

Step 5: Now we are adding viewcontroller class in the project. Select classes -> Add -> NewFile ->UIViewControllersubclass , save it , give the name PageControlExampleViewController.m,make sure that, it creates .h file also. Create a .xib file and give the name PageControllerExample.

Step 6: In the ViewController header file , we’ll create UILabel for display the page number, and mention one method. Make the following changes in the PageControlExampleViewController.h file.




Step 7: Now double click your PageControlExample.xib file and open it to the Interface Builder. Drag label from the library and place it on the View Window. Double click it and change the name into “1”. Now Connect the File’s Owner icon to the label and select ¬†pageNumberLabel. Save it and go back to the Xcode.

Step 8: Make the following changes in the PageControlExampleAppDelegate.m file.




Step 9: In the PageControlExampleViewController.m file make the following changes.




Step 10: Now compile and run the application in the simulator.

You can downloaded SourceCode from here PageControlExample