Swift 5.7 | What's new in UIPageControl ?

Photo by Bradyn Trollip on Unsplash

Get Started

Set background style of UIPageControl

/*
The preferred background style. Default is UIPageControlBackgroundStyleAutomatic on iOS, and UIPageControlBackgroundStyleProminent on tvOS.
*/
var backgroundStyle: UIPageControl.BackgroundStyle

Set indicator image for all pages of UIPageControl

/*
The preferred image for indicators. Symbol images are recommended. Default is nil.
*/
var preferredIndicatorImage: UIImage?

Get indicator image for UIPageControl’s specific page

/*
Returns the override indicator image for the specific page, nil if no override image was set.
Page must be in the range of 0..numberOfPages
*/
func indicatorImage(forPage page: Int) -> UIImage?

Set indicator image for UIPageControl’s specific page

/*
Override the indicator image for a specific page. Symbol images are recommended.
Resets to the default if image is nil.
Page must be in the range of 0..numberOfPages
*/
func setIndicatorImage(_ image: UIImage?, forPage page: Int)

What’s are the new updates in WWDC22 ?

Set the indicator image only for preferred current page of UIPageControl

/*
The preferred image for the current page indicator. Symbol images are recommended. Default is nil.
If this value is nil, then UIPageControl will use \c preferredPageIndicatorImage (or its per-page variant) as the indicator image.
*/
var preferredCurrentPageIndicatorImage: UIImage?

Set current page indicator image for specific page of UIPageControl

/*
Override the current page indicator image for a specific page. Symbol images are recommended.
Resets to the default if image is nil.
Page must be in the range of 0..numberOfPages
*/
func setCurrentPageIndicatorImage(_ image: UIImage?, forPage page: Int)

Get the current page indicator image from UIPageControl

/*
Returns the override current page indicator image for the specific page, nil if no override image was set.
Page must be in the range of 0..numberOfPages
*/
func currentPageIndicatorImage(forPage page: Int) -> UIImage?

Sample code with design

self.pageControl.numberOfPages = self.list.countself.pageControl.backgroundStyle = .prominentself.pageControl.preferredIndicatorImage = UIImage(systemName: "heart.fill")self.pageControl.setIndicatorImage(UIImage(systemName: "trash"), forPage: 1)self.pageControl.preferredCurrentPageIndicatorImage = .addself.pageControl.setCurrentPageIndicatorImage(.remove, forPage: 2)
example

One more update in UIPageControl:

Direction

natural
leftToRight
rightToLeft
topToBottom
bottomToTop
self.pageControl.direction = .bottomToTop
UIPageControl with all directions

Summary

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store