5

Completely stumped. I've looked all over and implemented every solution I could find. I can't seem to get the navigation bar to become transparent.

When trying to set the background color, I just get a black bar at the top. Same as if I try to set the background images. I've tried all of these and all of there many variations.

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

I'm using it in viewWillAppear() and in an animation when scrolling. The navigation bar is transparent, and then as you scroll navigation bar gets a white background with gray text.

  func scrollViewDidScroll(_ scrollView: UIScrollView) {
    self.navigationController?.navigationBar.barStyle = .default
    let offset =  self.tableView.contentOffset.y
    if offset > 250.0 {
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.darkGray]
        self.navigationController?.navigationBar.topItem?.title = spot!.Name
        self.navigationController?.navigationBar.isTranslucent = false
        self.navigationController?.navigationBar.tintColor = UIColor.darkGray
        self.navigationController?.isNavigationBarHidden = false
        self.navigationController?.navigationBar.barTintColor = UIColor.white
    }
    else {

        self.navigationController?.navigationBar.topItem?.title = nil
        self.navigationController?.navigationBar.isTranslucent = true
        self.navigationController?.isNavigationBarHidden = false
        self.navigationController?.navigationBar.tintColor = UIColor.white

        self.navigationController?.navigationBar.barTintColor = UIColor.white
        self.navigationController?.navigationBar.shadowImage = UIImage()

    }
}

Here's what it looks like...

I've also tried setting the background color to white, and changing the alpha = 0, but that doesn't work either.

Any help greatly appreciated.

menq
  • 391
  • 2
  • 10
chuninator
  • 63
  • 1
  • 6

1 Answers1

-1

This is because the window's background color is black and

You should set window?.backgroundColor = UIColor.white

in the AppDelegate application didFinishLauchingWithOptions method

menq
  • 391
  • 2
  • 10
  • That helps, but I still can't get it to full transparency... I've got a full white bar at the top now! – chuninator Mar 04 '17 at 23:21
  • 1
    I tried your method, and I works for me, check your scrollview's y to see if it's under the navbar – menq Mar 05 '17 at 12:18