Post

A PageControl with Simple Animations

An animated UIPageControl

A PageControl with Simple Animations

An open source PageControl with simple animations, supporting Auto Layout. The project is available on GitHub.

There are currently four styles to choose from:

  • LCSquirmPageStyle image1
  • LCScaleColorPageStyle image2
  • LCDepthColorPageStyle image3
  • LCFillColorPageStyle image4

Example

1
2
3
4
5
6
7
8
9
10
11
self.pageControl.numberOfPages = 5; // number of indicators
self.pageControl.indicatorMargin = 5.0f; // spacing between indicators, default is 0
self.pageControl.indicatorMultiple = 1.6f; // indicator scale factor, default is 2
self.pageControl.indicatorDiameter = 10.0f; // indicator diameter
pageControl.pageIndicatorColor = [UIColor grayColor]; // color in normal state
pageControl.currentPageIndicatorColor = [UIColor redColor]; // color in current state
self.pageControl.pageStyle = LCScaleColorPageStyle; // style
self.pageControl.sourceScrollView = _collectionView; // bind the scroll view
[self.pageControl prepareShow]; // call this after all properties are set
[self.view addSubview:_pageControl];

Note that the spacing adjusted by indicatorMargin is the distance between two indicators when both are in the enlarged state. Diagram: 2

In the ScaleColorPageStyle style, if the scroll view does not scroll to an adjacent position, you must implement the following protocol method and call clearIndicators:

1
2
3
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;{
    [self.pageControl clearIndicators];
}

Also, just like the native UIPageControl, listening for changes in the currently displayed indicator uses the target-action pattern:

1
[pageControl addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
This post is licensed under CC BY 4.0 by the author.