gpt4 book ai didi

ios - 带有大标题的 UINavigationBar 没有背景图片

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:02:24 25 4
gpt4 key购买 nike

我在更新应用程序时遇到了一个问题,以便 UINavigationBar 实例显示大标题。问题是,在我的应用程序的某些屏幕中,我不希望 UINavigationBarshadowbackgroundColor,所以我有一个将其外观从“固态”状态更改为“透明”状态并向后更改的方法。这是代码:

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
}
}

如您所见,此方法所做的只是更改 translucent 属性并设置/取消设置 shadowImagebackgroundImage。这在不使用大标题的情况下工作得很好,我附上了设置透明外观的图像:

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

对于大标题,这仍然可以正常工作;将外观类型设置回“实体”后出现问题。我附上另外两张显示问题的图片:

UINavigationBar still doesn't have background

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

所以问题是,只有在 navigationBar 不显示大标题时才会显示背景。我不知道我是否必须更改另一个属性,否则这不适用于大标题。任何帮助将不胜感激,在此先感谢。

最佳答案

我也遇到了这个问题。我的解决方法是将 UINavigationController 的 UIView 的背景颜色设置为 UINavigationBar 应该具有的背景颜色。

然后将 UINavigationBar 颜色设置为 UIClear 和半透明,并确保带有大标题的 UIViewController 不应将其边缘延伸到顶部栏下方。

它基本上是将导航 Controller 的背景设置为导航栏的背景,并将顶部的所有背景设置为半透明。

关于ios - 带有大标题的 UINavigationBar 没有背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51157306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com