skip to Main Content

I have issue with Navigation Controller inside TabBarController. I have 5 view controllers and 3 of them have navigation bar. I need to make white status bars of all of this 3 VC. And i can do it with

 self.navigationController?.navigationBar.barStyle = UIBarStyle.black

But here is the problem. When i push another View Controller and return back my status bar again become black

Here is my code for every VC

1st VC:

 override func viewDidLoad() {
    super.viewDidLoad()
    setupSearchBar()
    setupTableView()
    createAd()
    let label = UILabel()
    label.textColor = UIColor.white
    label.text = "Library"
    label.font = UIFont.boldSystemFont(ofSize: 35)
    if #available(iOS 13.0, *) {
          // Always adopt a light interface style.
          overrideUserInterfaceStyle = .light
      }
    navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: label)
    navigationItem.rightBarButtonItem = UIBarButtonItem.init(image: UIImage(named:"settingsButton"), style: .plain, target: self, action: #selector(self.action(sender:)))
    self.navigationController?.navigationBar.barStyle = UIBarStyle.black
}

2nd VC:

  override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBar.barStyle = UIBarStyle.black
    configureSegmentsContainer()
    configurSegments()
    setupCollectionView()
    
    if #available(iOS 13.0, *) {
          // Always adopt a light interface style.
          overrideUserInterfaceStyle = .light
      }
    
}

and 3rd:

 override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBar.barStyle = UIBarStyle.black
    setupTabelView()
    configure()
    setupNavBar()
    if #available(iOS 13.0, *) {
          // Always adopt a light interface style.
          overrideUserInterfaceStyle = .light
      }
}

What I am doing wrong and how i can fix it. PLS HELP

2

Answers


  1. Solution 1

        override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
            navigationController?.navigationBar.barStyle = .black
        }
    

    Solution 2

    class BaseNavigationControllerDark: UINavigationController {
        
        override func viewDidLoad() {
            super.viewDidLoad()
            navigationBar.barStyle = .black
        }
    }
    

    embed vc1 in BaseNavigationController and but not the other two just simple push vc2 or more

    //replace this 
    let vc = UINavigationController(rootViewController: vc1) 
    //to this
    let vc = BaseNavigationControllerDark(rootViewController: vc1)
    
    Login or Signup to reply.
  2. Try like this image i believe it will help you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search