Make navigation bar transparent regarding below image in iOS 8.1

前端 未结 4 1190
后悔当初
后悔当初 2020-12-16 04:32

I try to set my navigation bar transparent regarding a image below this, something like the following image :

\"

相关标签:
4条回答
  • 2020-12-16 05:12

    Have you tried setting the navigationBar's alpha property? In your root view controller to the navigation controller...

    [self.navigationController.navigationBar setBackgroundColor:[UIColor greenColor]];
    [self.navigationController.navigationBar setAlpha:0.3f];
    
    0 讨论(0)
  • 2020-12-16 05:16

    To set this style globally, use the UIAppearance APIs. In AppDelegate's application:didFinishLaunchingWithOptions: add the following code:

    // Sets background to a blank/empty image
    UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarMetrics: .Default)
    // Sets shadow (line below the bar) to a blank image
    UINavigationBar.appearance().shadowImage = UIImage()
    // Sets the translucent background color
    UINavigationBar.appearance().backgroundColor = UIColor(red: 0.0, green: 0.3, blue: 0.5, alpha: 0.3)
    // Set translucent. (Default value is already true, so this can be removed if desired.)
    UINavigationBar.appearance().translucent = true
    
    0 讨论(0)
  • 2020-12-16 05:16
    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController?.navigationBar.shadowImage = UIImage()
    self.navigationController?.navigationBar.backgroundColor = UIColor.clear
    self.navigationController?.navigationBar.isTranslucent = true
    

    If the above code is not working then set edgesForExtendedLayout to all.

    self.edgesForExtendedLayout = .all
    
    0 讨论(0)
  • 2020-12-16 05:32

    just checked on the 8.1 simulator and got very similar result to your picture

        let bar:UINavigationBar! =  self.navigationController?.navigationBar
    
        bar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
        bar.shadowImage = UIImage()
        bar.backgroundColor = UIColor(red: 0.0, green: 0.3, blue: 0.5, alpha: 0.3)
    

    main point here is background color with alpha.

    Check attached image, maybe I missed something?

    enter image description here

    0 讨论(0)
提交回复
热议问题