快速发送ui数据

问题描述 投票:0回答:2

我是SWIFT的初学者,现在我正面临着一个问题。在这个PHOTO我正在展示我的UI,以澄清我在说什么。在第1部分中,我检查用户是否登录到他的帐户,如果是,则转到第3部分,如果不是,则转到第2部分。当用户登录第2部分时,我将用户转移到第3部分。第1部分2应该没有任何导航颜色,但第3部分应该有导航颜色。

第1部分:

if let token = UserDefaults.standard.string(forKey: ConstantsKey.token){
        if !token.isEmpty{
            let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "MainTabBarVC")
            let rootController = UINavigationController(rootViewController: vc)
            self.present(rootController, animated: true, completion: nil)
        }else{
            let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "LoginVc")
            let rootController = UINavigationController(rootViewController: vc)
            self.present(rootController, animated: true, completion: nil)
        }
    }else{
        let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "LoginVc")
        let rootController = UINavigationController(rootViewController: vc)
        self.present(rootController, animated: true, completion: nil)
    }

第2部分:

let storyboard : UIStoryboard = UIStoryboard(name: "MainTabBar", bundle: nil)
                        let vc = storyboard.instantiateViewController(withIdentifier: "MainTabBarVC")
                        let rootController = UINavigationController(rootViewController: vc)
                        self.present(rootController, animated: true, completion: nil)

我希望在第3部分中有红色!但每当我运行应用程序时,都会显示导航控制器的defualt颜色

有谁知道我应该如何管理/处理这个问题?

ios iphone swift user-interface uinavigationcontroller
2个回答
2
投票

然后在第1部分:

    if !token.isEmpty{
                let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                let vc = storyboard.instantiateViewController(withIdentifier: "MainTabBarVC")
                let rootController = UINavigationController(rootViewController: vc)
                rootController?.navigationBar.barTintColor = UIColor.red
                self.present(rootController, animated: true, completion: nil)

第2部分:

let storyboard : UIStoryboard = UIStoryboard(name: "MainTabBar", bundle: nil)
                        let vc = storyboard.instantiateViewController(withIdentifier: "MainTabBarVC")
                        let rootController = UINavigationController(rootViewController: vc)
                        rootController?.navigationBar.barTintColor = UIColor.red
                        self.present(rootController, animated: true, completion: nil)

0
投票

登录时设置

UserDefaults.standard.set(true,forKey: ConstantsKey.token)

在路由页面检查这个

if UserDefault.standar.bool(forKey: ConstantsKey.token){
   //Go to home page
}else {
   setUpNav()
   //Go to login page
}

设置导航

这个将为整个应用程序设置

    func setUpNav(){
            UINavigationBar.appearance().isTranslucent = false
            UINavigationBar.appearance().tintColor = UIColor.red
            UINavigationBar.appearance().barTintColor  = UIColor.white


            UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white,
                                                                NSAttributedStringKey.font: UIFont(name:"Cairo-Bold", size:22.0)!]
        }

如果你想要单个VC,

在VC中写这个,

确保VC的root是navigationController

self.navigationController.navigationBar.barTintColor = .white
self.navigationController.navigationBar.tintColor = .red

即使你没有设置任何值,它也不会崩溃!!

© www.soinside.com 2019 - 2024. All rights reserved.