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.