user567
user567

Reputation: 3842

Chaning the position of UIPageControl not working

I am adding a UIPageControle view to a UIPageViewController. I want to increase the height of the UIPageControler programmatically. This is my code

//PageViewController
pageViewController.view.frame = bounds

// pageControl
self.pageControl.frame = CGRect(x: 0, y: 0, width: pageViewController.view.frame.width / 2, height: pageViewController.view.frame.height - 200)
self.pageControl.currentPageIndicatorTintColor = UIColor.orange
self.pageControl.pageIndicatorTintColor = UIColor.white
self.pageControl.numberOfPages = self.pages.count
self.pageControl.currentPage = initialPage
pageViewController.view.addSubview(self.pageControl)

The UIPageControle still in the middle and at the bottom of the UIPageViewController. Even if I set random values such as

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

the UIpageController position never changes

Upvotes: 0

Views: 510

Answers (1)

David Kadlcek
David Kadlcek

Reputation: 476

If you want to change the location of UIPageControl. You must write constraints. I write that code to ViewDidLoad()

view.addSubview(pageControl)
        pageControl.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        pageControl.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        pageControl.heightAnchor.constraint(equalToConstant: 60).isActive = true
        pageControl.widthAnchor.constraint(equalToConstant: 30).isActive = true

I don't think, that you can change the height, but you can create your own UIView or download pods

Upvotes: 1

Related Questions