SMPageControl – a custom page control

Page Control Swift

Since the native UIPageControl is not editable to the level we sometimes need, we need to seek for other available custom controls that are on the web. To save you time in research and googling around, I present you my personal favorite custom page control library and the one I have used in many projects, called SMPageControl.

Let me guide you through the implementation of this library in your project…

The first thing you need to do is to add pod ‘SMPageControl’, ‘~> 1.2’ to your Podfile (if you are a CocoaPods user).

Then import the SMPageControl.h class in your desired view and add this snippet below:

    self.pageControl = [[SMPageControl alloc] init];
    self.pageControl.numberOfPages = 10;
    self.pageControl.pageIndicatorImage = [UIImage imageNamed:@"pageDot"];
    self.pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"currentPageDot"];
    [self.pageControl sizeToFit];
    [self.view addSubview:self.pageControl];

    // To track what is the current page you will use
    NSLog("Current Page: %ld",self.pageControl.currentPage);

This snippet will add the SMPageControl to your view and give you an option to add custom images for selected/unselected state, which is not the case in the native UIPageControl.

The library supports Accessibility features as well.

Leave a Reply

Your email address will not be published. Required fields are marked *