如何更改 swift 上覆盖缺口区域的条形色调颜色(uikit)
How to change bar tint color that covers the notch area on swift (uikit)
我正在尝试将 barTintColor
从 SceneDelegate
更改为 barTintColor
,但它没有覆盖整个顶部区域。看看我的 ss:
如何让它覆盖整个顶部区域?
这是我的代码,提前谢谢你。
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
UINavigationBar.appearance().barTintColor = UIColor(displayP3Red: 47/225, green: 54/225, blue: 64/225, alpha: 1.0)
UINavigationBar.appearance().backgroundColor = UIColor(displayP3Red: 47/225, green: 54/225, blue: 64/225, alpha: 1.0)
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}
}
这应该只用一行:
UINavigationBar.appearance().barTintColor = .yellow
所以,显然是因为 iOS 版本。 Pre iOS 13 可以与 just
一起使用
UINavigationBar.appearance().barTintColor = .yellow
但现在有点不一样了。所以对于这个人,我找到了答案
所以我现在要做的是:
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .red
UINavigationBar.appearance().standardAppearance = appearance // for scrolling bg color
UINavigationBar.appearance().compactAppearance = appearance // not sure why it's here, but u can remove it and still works
UINavigationBar.appearance().scrollEdgeAppearance = appearance // for large title bg color
这至少对我有用。
我正在尝试将 barTintColor
从 SceneDelegate
更改为 barTintColor
,但它没有覆盖整个顶部区域。看看我的 ss:
如何让它覆盖整个顶部区域?
这是我的代码,提前谢谢你。
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
UINavigationBar.appearance().barTintColor = UIColor(displayP3Red: 47/225, green: 54/225, blue: 64/225, alpha: 1.0)
UINavigationBar.appearance().backgroundColor = UIColor(displayP3Red: 47/225, green: 54/225, blue: 64/225, alpha: 1.0)
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}
}
这应该只用一行:
UINavigationBar.appearance().barTintColor = .yellow
所以,显然是因为 iOS 版本。 Pre iOS 13 可以与 just
一起使用UINavigationBar.appearance().barTintColor = .yellow
但现在有点不一样了。所以对于这个人,我找到了答案
所以我现在要做的是:
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = .red
UINavigationBar.appearance().standardAppearance = appearance // for scrolling bg color
UINavigationBar.appearance().compactAppearance = appearance // not sure why it's here, but u can remove it and still works
UINavigationBar.appearance().scrollEdgeAppearance = appearance // for large title bg color
这至少对我有用。