Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIN航空标题颜色更改问题_Ios_Uinavigationcontroller_Uinavigationbar - Fatal编程技术网

Ios UIN航空标题颜色更改问题

Ios UIN航空标题颜色更改问题,ios,uinavigationcontroller,uinavigationbar,Ios,Uinavigationcontroller,Uinavigationbar,当我弹出控制器时,我面对的导航标题颜色没有改变。请查找下面的代码 ProfilescreenVC.swift override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.navigationController?.navigationBar.tintColor = UIColor.white self.navigationControlle

当我弹出控制器时,我面对的导航标题颜色没有改变。请查找下面的代码

ProfilescreenVC.swift
override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.tintColor = UIColor.white
        self.navigationController?.navigationBar.barTintColor = UIColor.primaryGreen
        let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
        self.navigationController?.navigationBar.titleTextAttributes = textAttributes
    }
编辑:vc.swift

override func viewDidLoad() {
        super.viewDidLoad()        
        self.style()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func style() {
        navigationController?.navigationBar.tintColor = UIColor.black
        navigationController?.navigationBar.barTintColor = UIColor.white
        let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
        navigationController?.navigationBar.titleTextAttributes = textAttributes

        carbonTabSwipeNavigation.setIndicatorColor(UIColor.black)
        carbonTabSwipeNavigation.setTabBarHeight(50.0)
        carbonTabSwipeNavigation.setNormalColor(UIColor.hexString("9A9CA1"), font: UIFont.systemFont(ofSize: 15))
        carbonTabSwipeNavigation.setSelectedColor(UIColor.black, font: UIFont.systemFont(ofSize: 15))

        self.navigationController?.view.setNeedsLayout()
        self.navigationController?.view.layoutIfNeeded()
    }

    override func viewDidDisappear(_ animated: Bool) {
        navigationController?.navigationBar.tintColor = UIColor.white
        navigationController?.navigationBar.barTintColor = UIColor.white
        let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
        navigationController?.navigationBar.titleTextAttributes = textAttributes
        super.viewDidDisappear(animated)
    }
我有一个标题的颜色变化面临的问题,请检查以下更好的理解

ProfilescreenVC.swift

override func viewWillAppear(_ animated: Bool) 
{
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.tintColor = UIColor.white
        self.navigationController?.navigationBar.barTintColor = UIColor.primaryGreen
        let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
        self.navigationController?.navigationBar.titleTextAttributes = textAttributes
    }
而在VC中

override func viewWillAppear(_ animated: Bool) 
        {
    navigationController?.navigationBar.tintColor = UIColor.black
            navigationController?.navigationBar.barTintColor = UIColor.white
            let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.black]
            navigationController?.navigationBar.titleTextAttributes = textAttributes
    }

无需在代码中添加
ViewDidDisapper

这似乎是一个棘手的问题,导航栏的标题属性仅通过向前应用

在尽我所能尝试之后,我决定采用以下解决方法,在navigationItem中提供我自己的标题视图

    let titleView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
    titleView.backgroundColor = UIColor.clear
    let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
    titleLabel.textAlignment = .center
    titleLabel.text = "Profile"
    titleLabel.textColor = .white
    titleView.addSubview(titleLabel)
    self.navigationItem.titleView = titleView
    self.navigationItem.title = "Profile"

请注意,您还需要在navigationItem.title中提供标题,以便在向前导航时正确设置“后退”按钮。

我认为此链接将对您有所帮助