Swift导航栏背景颜色白色不工作 [英] Swift Navigation bar background color white does not work

查看:614
本文介绍了Swift导航栏背景颜色白色不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个困难的时间,试图将navigationBar.barTintColor更改为白色。奇怪的是,所有其他颜色都可以工作,但不是白色!

Im having a difficult time trying to change the navigationBar.barTintColor to white. Strangely, all other colors work, but not white!

self.navigationController!.navigationBar.barTintColor = UIColor.whiteColor()

以上行不适用于白色。

甚至尝试了一个背景图像。还是一样。任何其他颜色的作品,但不是白色!白色总是被浅灰色代替...

Even tried with a background image. Still the same. Any other color works but not white!! White is always replaced by light grey...

请指教我在哪里出错...

Please advice where I am going wrong...

感谢。

推荐答案

请尝试以下代码:

在您的viewDidLoad:

In your viewDidLoad:

    title = "Some Title"

    UIApplication.shared.statusBarStyle = .default
    navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
    navigationController?.navigationBar.shadowImage = UIImage()
    navigationController?.navigationBar.isTranslucent = true

    //Line under NavigationBar
    let barView = UIView(frame: CGRect(x:0, y:(UINavigationController().navigationBar.frame.height + UIApplication.shared.statusBarFrame.height), width:view.frame.width, height:0.6))
    barView.backgroundColor=UIColor.red // set any colour you want..
    navigationController?.navigationBar.addSubview(barView)

    //Title Colour
     navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.red]

注意

以上代码适用于任何背景颜色....
如果您希望导航栏为绿色... .set your view background color to green ...

Above code works on any background colour.... If you want the navigationBar to be green....set your view background colour to green...

这篇关于Swift导航栏背景颜色白色不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆