iOS13 Navigation bar large titles not covering status bar

The official way to customize the UINavigationBar, pre iOS 13, is this:

// text/button color
UINavigationBar.appearance().tintColor = .white
// background color
UINavigationBar.appearance().barTintColor = .purple
// required to disable blur effect & allow barTintColor to work
UINavigationBar.appearance().isTranslucent = false

iOS 13 has changed how navigation bars work, so you’ll need to do things slightly differently to support both old & new:

if #available(iOS 13.0, *) {
    let appearance = UINavigationBarAppearance()
    appearance.backgroundColor = .purple
    appearance.titleTextAttributes = [.foregroundColor: UIColor.white]
    appearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]

    UINavigationBar.appearance().tintColor = .white
    UINavigationBar.appearance().standardAppearance = appearance
    UINavigationBar.appearance().compactAppearance = appearance
    UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
    UINavigationBar.appearance().tintColor = .white
    UINavigationBar.appearance().barTintColor = .purple
    UINavigationBar.appearance().isTranslucent = false
}

Leave a Comment