iOS: Remove padding in UIPageControl

Viewed 1077

I have an app with compatibility from iOS 12 to 14 and have a problem with the page control. On iOS 14 it has a huge padding which it doesn't have in older iOS version. Interface builder also shows this padding. My Problem is that I don't want this because my page control is not centred but left aligned in the UI.

enter image description here

How can I remove the padding so that it looks identically on all iOS versions?

2 Answers

This issue is because of ios 14. I used below combination of code for ios 14 and it worked like a charm

if #available(iOS 14.0, *) {
  pageControl.backgroundStyle = .minimal
  pageControl.allowsContinuousInteraction = false
}

The only solution I could find was to create outlets for the page control constraints and change their constants to adjust the control's position for iOS 14. Here's my code: (My control is right aligned, so you should adjust for left alignment)

    // iOS 14 introduced extra padding to the UIPageControl. We adjust its constraints to keep it displayed in the lower right corner of the superview
    if #available(iOS 14, *)
    {
        pageControlTrailingConstraint.constant = -30
        pageControlBottomConstraint.constant = -3
    }
Related