【问题标题】:navigation bar title isn't changing [duplicate]导航栏标题没有改变[重复]
【发布时间】:2020-04-09 12:37:50
【问题描述】:

这是 AppDelegate 代码,我正在运行 swift 5。您对为什么我的导航栏标题颜色仍然是黑色有任何想法吗?

var navigationBarAppearance = UINavigationBar.appearance()
var tabBarAppearance = UITabBar.appearance()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    FirebaseApp.configure()
    navigationBarAppearance.tintColor = UIColor.white
    tabBarAppearance.tintColor = UIColor.white
    navigationBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
    print(Realm.Configuration.defaultConfiguration.fileURL!)
    do{
        let _ = try Realm()
    }catch{
        print("Error initializing new realm, \(error)")
    }

    return true
}

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    在方法中添加这些行

    var navigationBarAppearance = UINavigationBar.appearance()
    var tabBarAppearance = UITabBar.appearance()
    

    应该是这样的

     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    
        FirebaseApp.configure()
        var navigationBarAppearance = UINavigationBar.appearance()
        var tabBarAppearance = UITabBar.appearance()
        navigationBarAppearance.tintColor = UIColor.white
        navigationBarAppearance.barTintColor = UIColor.white
        tabBarAppearance.tintColor = UIColor.white
        navigationBarAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
        print(Realm.Configuration.defaultConfiguration.fileURL!)
        do{
            let _ = try Realm()
        }catch{
            print("Error initializing new realm, \(error)")
        }
    
        return true
    }
    

    最后,我了解您的问题,它仅适用于最新的 ios。如果您使用的是 ios 13.4.1
    ,您还需要一些附加功能 然后使用此代码:

     let coloredAppearance = UINavigationBarAppearance()
     coloredAppearance.configureWithOpaqueBackground()
     coloredAppearance.tintColor = UIColor.white
     coloredAppearance.barTintColor = UIColor.white
     ....         
    UINavigationBar.appearance().standardAppearance = coloredAppearance
    UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
    

    应该没问题。

    【讨论】:

    • 我试过这个,但没有帮助
    • 也许你也可以尝试添加 navigationBarAppearace.barTintColor = UIColor.white
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-24
    • 2011-01-09
    • 2017-08-23
    • 2013-09-28
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多