Search code examples
swiftxcodeuinavigationcontrolleruinavigationbaruipageviewcontroller

Bar Button Doesn't Appear in PageViewController


I'm learning Swift. I tried adding a button in the UIPageViewController but it didn't show when I run the application. It showed the default back button instead. I tried adding it to a UIViewController and it worked. I already added a navigational bar before inserting the BarButtonItem but it still won't show. Why is it? How do I add the button into the navigation bar of the UIPageViewController?

Expected Navigation Menu Actual Navigation Menu
enter image description here enter image description here


Solution

  • if you are pushing to pageviewcontroller then try this :-

     let myAttribute2 = [ NSForegroundColorAttributeName: UIColor.white 
     ,NSFontAttributeName: UIFont(name: kFontname, size: 20.0)]
        self.navigationController?.navigationBar.isTranslucent = false
        self.navigationController?.navigationBar.titleTextAttributes = myAttribute2
        self.navigationController?.isNavigationBarHidden = false
        self.navigationController?.navigationBar.barTintColor = kNavigationColor
        let img = UIImage(named: "menu-icon")
        let menuBtn = UIBarButtonItem(image: img, style: .plain, target: self, action: #selector(self.menuAction))
        self.navigationItem.leftBarButtonItem = menuBtn