ios - 如何设置iOS 13深色模式大标题颜色?

标签 ios uinavigationbar ios13 ios-darkmode large-title

在我的应用程序中我使用

let navigationBar = UINavigationBar.appearance()
navigationBar.largeTitleTextAttributes = [
    NSAttributedString.Key.font: UIFont.SFProDisplay(ofSize: 34, weight: .bold),
    NSAttributedString.Key.foregroundColor: UIColor.custom
]

static var custom: UIColor {
    return UIColor(named: "color_custom")!
}

color set

其中有一个颜色集 color_custom。 但是在颜色模式之间切换时,它仅使用 Any Appearance 颜色。未使用深色外观。为什么?

添加:

经过一些研究后,我认为应该添加下一个问题:在我的应用程序中,我使用切换器在模式之间切换。 Storage.isDarkModeOn = newState//保存在用户默认值中。然后:

class PapaViewController: UIViewController {
    if #available(iOS 13.0, *) {
        overrideUserInterfaceStyle = Storage.isDarkModeOn ? .dark : .light
    }
}

PapaViewController 是我应用中所有 UIViewController 的父类。因此,如果 overrideUserInterfaceStyle == .dark 和设备颜色模式 == .light 错误就会出现。如果然后我将设备颜色模式更改为 .dark,则大标题看起来符合预期。

最佳答案

现在显示的代码的问题仅仅是您与错误的 View Controller 对话。您需要更改其覆盖的不是您的 View Controller (self):它是 View Controller ,在本例中可能是导航 Controller 。

class PapaViewController: UIViewController {
    if #available(iOS 13.0, *) {
        self.navigationController?.overrideUserInterfaceStyle = // ...
    }
}

关于ios - 如何设置iOS 13深色模式大标题颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58187167/

相关文章:

iOS 13 - 大标题中的变音符号导致内容跳跃和警告 UITableViewAlertForLayoutOutsideViewHierarchy

ios - 在 iOS 13 全屏中呈现模式

iphone - 使用段控制优化核心数据获取请求

ios - iTunes Connect 应用本地化

ios - 获取 UITextView 的内容高度

ios - 'UINavigationController ?' does not have a member named ' 导航栏'

ios - 消除 UINavigationBar 上栏左侧和 leftBarButtonItem 之间的空间

ios - 根据触摸速度绘制

iphone - iOS 内存泄漏导致更改 View Controller 时崩溃

当用户按下 ios13 时,iOS 应用程序崩溃