Transparent UINavigationBar in Swift

后端 未结 6 977
感动是毒
感动是毒 2020-12-13 06:43

I am trying to make my UINavigationBar in UINavigationController transparent. I created a subclass of UINavigationController and liked

6条回答
  •  爱一瞬间的悲伤
    2020-12-13 06:58

    Hope it help you

    Swift 2:

    self.navigationController.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
    self.navigationController.navigationBar.shadowImage = UIImage()
    self.navigationController.navigationBar.isTranslucent = true
    self.navigationController.view.backgroundColor = UIColor.clearColor()
    

    Swift 4.2 to Swift 5.1

    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
    self.navigationController?.navigationBar.shadowImage = UIImage()
    self.navigationController?.navigationBar.isTranslucent = true
    self.navigationController?.view.backgroundColor = UIColor.clear
    

    Or If you want to sublcass the navigation controller then refer this answer.


    Change the status bar style via :

    In your Info.plist you need to define View controller-based status bar appearance to any value.

    enter image description here

    UIApplication.shared.statusBarStyle = .lightContent
    

    If you want to hide the status bar:

    UIApplication.shared.isStatusBarHidden = true
    

    Getting this output by light content and by transparent navigation. I have view background is gray. you can see the transparency.

    enter image description here

    iPhone XR - Swift 4.2 - Large Titles (Test Screenshot)

提交回复
热议问题