How To Best Resize SMPageControl Indicators to Fit Bounds
I have been working on a new feature for my Hourly News
iOS App that allows the addition of custom news sources to the app.
While testing out what happens when a customer adds dozens of feeds,
I noticed a problem with UIPageControl
…
… it doesn't resize itself to fit within its bounds, and it draws outside of them! So, I started shopping around for an open-source replacement,
landing on SMPageControl for its customization level,
its stability and its longevity. Swapping the UIPageControl
for the SMPageControl
was pretty straightforward,
and it solved the problem of drawing outside of its bounds easily enough.
However, when there were more pages than room to fit them, the leading and trailing pages were cut off from the view.
Because SMPageControl
allows for the customization of the indicator size and margin between them,
I wrote a little function that adjusted these values to ensure that all pages will fit and be displayed, within reason.
Basically, it checks the calculated full width of the page control, and while that width is wider than the page control's bounds, alternate a reduction of the indicator margin and diameter until it fits, or until it hits a reasonable minimum size. I call this in viewDidLoad
, willAnimateRotationToInterfaceOrientation
and also whenever a source is added or removed from the app. Looks much better!
Lastly, I run a small software company called Urban Apps. It pays the bills so I can take the time to write helpful posts like this one. If you found this page helpful at all, I would really appreciate it if you would check out my Apps on the iTunes App Store.
Was this page helpful for you? Buy me a slice of 🍕 to say thanks!
Comments