The UIPageControl page control in iOS App development USES a summary

  • 2020-06-07 05:22:02
  • OfStack

The most typical application is the home screen of iPhone. When there are too many ICONS, the page will be added automatically. At the bottom of the screen, you will see the origin, which is only used for the current page, and will be updated automatically as the page is turned.
1. Create


UIPageControl* myPageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0.0, 400.0, 320.0, 0.0)]; 

2. Set the properties
The page number

myPageControl.numberOfPages =5; 

By default page 1 is selected. If you want to select another page, you can set the currentPage property. Page index starts at 0:

myPageControl.currentPage =3;// Current page number, no 4 page

By default, even if there is only one page, indicators are displayed. If you want to hide the indicator with only 1 page, you can set the value of hideForSinglePage to YES.

myPageControl.hidesForSinglePage=YES; 

If you want to update the current indicator the current indicator page until you have time to perform your actions, set defersCurrentPageDisPlay to YES. You must then call the control's updateCurentPageDisPlay to update the current page:

myPageControl.defersCurrentPageDisplay = YES; 
    [myPageControl updateCurrentPageDisplay]; 

3. Display controls

[self.view addSubview:myPageControl]; 

4. Notice
An UIControlEventVakueChanged event is generated when the user touches the paging control. You can specify an action for the addTarget method of the UIControl class:

-(void)pageChanged:(id)sender{ 
    UIPageControl* control = (UIPageControl*)sender; 
    NSInteger page = control.currentPage; 
    // Add the code you want to work with  
}   
[myPageControl addTarget:self action:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged]; 

5. Common properties 1


// create UIPageControl
UIPageControl * page = [[UIPageControl alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height-50, self.view.bounds.size.width, 50)];
 
// Set the background color
page.backgroundColor = [UIColor clearColor];
 
// Set the number of small circles
page.numberOfPages = 15;
 
// Set up the The color of the circles
page.pageIndicatorTintColor = [UIColor orangeColor];
 
// Sets the small circle color of the current page
page.currentPageIndicatorTintColor = [UIColor redColor];
 
// To obtain / Change current page
page.currentPage = 1;
 
// Add click events
[page addTarget:self action:@selector(pageClick:) forControlEvents:UIControlEventValueChanged];


Related articles: