2

I ran into a problem when I updated an app so that UINavigationBar instances displayed large titles. The thing is that in some screens in my app, I don't want the UINavigationBar to have either shadow or backgroundColor, so I have a method to change it's appearance from a "solid" state to a "transparent" one, and backwards. Here's the code:

public static func setNavAppearance(type: AppearanceType, navigationBar: UINavigationBar?) {

    if (type == .transparent) {
        navigationBar?.setBackgroundImage(UIImage.init(), for: .default)
        navigationBar?.shadowImage = UIImage.init()
        navigationBar?.isTranslucent = true
    }
    else {
        navigationBar?.shadowImage = nil
        navigationBar?.setBackgroundImage(nil, for: UIBarMetrics.default)
        navigationBar?.isTranslucent = false
    }
}

As you can see, all that this method does is changing the translucent property and setting / unsetting both shadowImage and backgroundImage. This worked fine without using large titles, there I attach and image of what setting transparent appearance does:

UINavigationBar without background image and shadow, but showing UIBarButtonItems and backButton

With large titles, this is still working fine; the problem comes after setting the appearance type back to "solid". I attach two more images displaying the problem:

UINavigationBar still doesn't have background

After scrolling up a bit so that large title is collapsed, background color appears

So the thing is, that background is only being displayed for the navigationBar when it is not displaying large titles. I don't know if I have to change another property or this won't work with large titles. Any help will be appreciated, thanks in advance.

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
  • 1
    i have a similar issue, has there been a solution found? – mding5692 Aug 11 '18 at 02:03
  • Did you manage to solve this? – Eduard Jan 21 '19 at 12:20
  • @Eduard No, I haven't found any valid solution. What I did was hide the navigation Bar when pushing and then add one to the view controller using the storyboard, and customize that one. The interactive gesture to go back is lost but, at least is a way for customizing the navBar the way we want. – Borja Pérez Guasch Feb 18 '19 at 11:17

1 Answers1

0

I also hit this issue. My workaround was to set the background color of the UIView of the UINavigationController to the background color that the UINavigationBar should have.

Then set the UINavigationBar color to UIClear and translucent, and make sure that the UIViewController with the large title should not extend its edges under the top bar.

It's basically setting the background of the nav controller to the background of the navbar, and setting all backgrounds on top to translucent.

Ch Ryder
  • 360
  • 3
  • 10