Paul Heuts
Paul Heuts

Reputation: 11

change PageControl height from UIPageViewControllerDataSource

I have a PageViewController set up and everything is working as it should. Currently I'm working on the GUI appearances, and running into some problems with the Page Indicator (UIPageControl).

I have set up the datasource of the PageViewController in an extension, and reference the UIPageControl from viewDidLoad() via UIAppearance as follow:

fileprivate func stylePageControl() {
        let pageControl = UIPageControl.appearance(whenContainedInInstancesOf: [type(of: self)])

        pageControl.currentPageIndicatorTintColor = UIColor(red:39/255.0, green:39/255.0, blue:39/255.0, alpha: 1.0)
        pageControl.pageIndicatorTintColor = UIColor(red:170/255.0, green:170/255.0, blue:170/255.0, alpha: 1.0)
        pageControl.backgroundColor = UIColor(red:56/255.0, green:56/255.0, blue:56/255.0, alpha: 1.0)

    }

The colors are changing without any trouble. But I'm unable to set the height of the PageControl. I tried all kinds of things with .frame and . layer, but nothing seems to work. I found similar question for objective-c with the following solution:

pageControl.frame = CGRectMake(x, y, width, height);

But since I'm working in Swift, CGRectMake is unavailable. And for some reason CGRect() doesn't do the trick:

pageControl.frame = CGRect(x:0, y:0, width:self.view.frame.width, height:300)

Any suggestions are more than welcome.
Thanks in advance.

Upvotes: 1

Views: 361

Answers (0)

Related Questions