13.7 C
Wednesday, May 15, 2024

ios – toolbarBackground modifier adjustments font of navigation bar – SwiftUI

I modify the font of the navigation bar like so,

init() {
    // Initialise Firebase

    // this isn't the identical as manipulating the proxy immediately
    let look = UINavigationBarAppearance()
    // this overrides the whole lot you've got arrange earlier.
    // this solely applies to large titles
    look.largeTitleTextAttributes = [
        .font : UIFont(name: "F37Bobby-Light", size: 38)!,
        NSAttributedString.Key.foregroundColor : UIColor(named: "Dark")!
    // this solely applies to small titles
    look.titleTextAttributes = [
        .font : UIFont(name: "Avenir", size: 20)!,
        NSAttributedString.Key.foregroundColor : UIColor(named: "Dark")!
    let again = UIBarButtonItemAppearance()
    again.regular.backgroundImage = UIImage(named: "arrow.left")
    again.regular.titleTextAttributes = [
        .font : UIFont(name: "Avenir", size: 20)!,
        NSAttributedString.Key.foregroundColor : UIColor(named: "Dark")!
    look.backButtonAppearance = again
    look.shadowColor = .clear
    #if !targetEnvironment(macCatalyst)
    look.backgroundColor = UIColor(named: "White")

    //Within the following two traces you just be sure you apply the fashion for good
    UINavigationBar.look().scrollEdgeAppearance = look
    UINavigationBar.look().standardAppearance = look
    // This property will not be current on the UINavigationBarAppearance
    // object for some motive and it's a must to depart it til the tip
    UINavigationBar.look().tintColor = UIColor(named: "Black")
    UINavigationBar.look().prefersLargeTitles = true
    UITextView.look().backgroundColor = .clear

    UINavigationBar.look().isTranslucent = false
    UIToolbar.look().backgroundColor = UIColor(named: "White")
    UIToolbar.look().isTranslucent = false

When including the next modifiers to a view

.toolbarBackground(.hidden, for: .tabBar
.toolbarBackground(.hidden, for: .navigationBar)

It adjustments the font again to default. Why is that this and the way can I modify the font/stop this from taking place?

Latest news
Related news


Please enter your comment!
Please enter your name here