How to make a transparent navigation bar transparent?

I want to make my navigation controller like this. My main opinion should go on to the top. enter image description here

But when I try to implement it, I get this result: enter image description here

How can I deal with this problem. I want to implement something like the first image. Can anyone help? Thanks

+4
source share
4 answers

I use this in my applications to make my navigation bar transparent (if the navigationBar is in the UINavigationController):

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true

Now you can add buttons and a title to your navigation block.

EDIT: Swift 3 (thanks DrBreakalot)

self.navigationController?.navigationBar.setBackgroundImage(‌​UIImage(), for: .default) 
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
+11
source

, , , . , " " .

, , viewDidLoad()

navigationController?.setNavigationBarHidden(true, animated: true)
+1

Here is the code to help you with this. What you do is a creature UIVisualEffectViewthat blurs the situation a bit, then you set it as a sub navBar.

func addBlurEffect() {
    let bounds = self.navigationController?.navigationBar.bounds as CGRect!
    let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
    visualEffectView.frame = bounds
    visualEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
    navigationController?.navigationBar.addSubview(visualEffectView)
}
0
source

It looks like your Autolayout is set to the top field, not the top. You should also change the status bar like this:AppDelegate

UIApplication.sharedApplication().statusBarStyle = .LightContent
0
source

Source: https://habr.com/ru/post/1627076/


All Articles