0

I use collectionView in my app and set status bar style to light and set hidesBarsOnSwipe of navigationController to true. But when I scroll cell up, navigationController is hides, but status bar turn to black color. and back to white when scroll collectionView to down. this is my code for navigationController:

extension UINavigationController {

    override open var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }

    func transparentNavigation() {

        guard let pacificoFont = UIFont(name: "Pacifico", size: 20) else {return}

        navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.foregroundColor, NSAttributedStringKey.font: pacificoFont]

        navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        navigationBar.shadowImage = UIImage()
        navigationBar.isTranslucent = true
        view.backgroundColor = .clear
        hidesBarsOnSwipe = true
    }

}

Is there any way to repair this "feature"?

Jack Daniel
  • 2,397
  • 8
  • 33
  • 58

1 Answers1

0

When you have a translucent Navigation bar, status bar gets its color from the Navigation bar. As a result when Navigation bar scrolls status bar falls to default black color.

If you want translucent Navigation bar and status bar to be of specific color (like white) you can use

You can add it in ViewDidLoad

    let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
    statusBar.backgroundColor = UIColor.white

Hope this helps

Sandeep Bhandari
  • 19,999
  • 5
  • 45
  • 78