我在我的应用程序中遇到了同样的问题。它曾经可以工作,但在某些时候所有控件都变成默认的蓝色而不是我的自定义颜色。我确认目标的构建设置中的全局强调颜色名称是正确的,并且资产目录已添加到该目标。
经过一番调试,终于找到了原因。这行代码破坏了全局强调色(使用 Xcode 14 beta 5 测试):
UINavigationBar.appearance().largeTitleTextAttributes = [.font : UIFont(descriptor: UIFontDescriptor.preferredFontDescriptor(withTextStyle: .largeTitle).withDesign(.rounded)!.withSymbolicTraits(.traitBold)!, size: 34)]
Run Code Online (Sandbox Code Playgroud)
然而,这样的事情并不会破坏它:
UINavigationBar.appearance().largeTitleTextAttributes = [.font: UIFont.systemFont(ofSize: 34)]
Run Code Online (Sandbox Code Playgroud)
超级奇怪。如果您有任何UINavigationBar
外观覆盖,请尝试将其注释掉,看看这是否会导致您的问题。
tintColor
作为一种解决方法,我正在做的是在 SceneDelegate 中设置窗口(为我的 SwiftUI 应用程序手动添加):
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
(scene as? UIWindowScene)?.keyWindow?.tintColor = UIColor(named: "AccentColor")
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1430 次 |
最近记录: |