Add UIPageControl to titleView swift

I am trying to add a UIPageControl to my navigationBar via titleView, but nothing is displayed in the navigationBar. I tried to add pageControl to UIView and then add UIView to titleView, but since I did not answer. How can I achieve this?

var pageControl: UIPageControl?
var pageView: UIView?


    pageView?.frame = CGRectZero
    pageView?.backgroundColor = UIColor.greenColor()
    pageControl?.frame = CGRectZero
    pageControl?.currentPage = 0
    pageControl?.numberOfPages = 3
    pageControl?.tintColor = UIColor.whiteColor()
    pageView?.addSubview(pageControl!)
    self.navigationController?.navigationItem.titleView = pageView?
+4
source share
1 answer

Do not look at the View page. But you need to create an instance of pageControl and add it to the navigationItem of the current viewController, and not to the navigationController navigationItem.

var pageControl: UIPageControl?
pageControl = UIPageControl()
pageControl?.frame = CGRectZero
pageControl?.currentPage = 0
pageControl?.numberOfPages = 3
pageControl?.tintColor = UIColor.whiteColor()
self.navigationItem.titleView = pageControl?
+3
source

All Articles