Swift导航栏背景颜色白色不起作用

2023-06-12移动开发问题
43

本文介绍了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...

谢谢.

推荐答案

试试这个代码:

在你看来DidLoad:

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]

注意:

以上代码适用于任何背景颜色....如果您希望导航栏为绿色....将您的视图背景颜色设置为绿色...

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

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

The End

相关推荐

无法将文件从捆绑包复制到 iOS 中的文档目录
Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)...
2024-04-15 移动开发问题
4

如何复制“字典"在斯威夫特?
How to copy a quot;Dictionaryquot; in Swift?(如何复制“字典在斯威夫特?)...
2024-04-15 移动开发问题
10

Swift - 迭代结构对象时如何对其进行变异
Swift - How to mutate a struct object when iterating over it(Swift - 迭代结构对象时如何对其进行变异)...
2024-04-15 移动开发问题
7

如何使用 Swift 将文本复制到剪贴板/粘贴板
How to copy text to clipboard/pasteboard with Swift(如何使用 Swift 将文本复制到剪贴板/粘贴板)...
2024-04-15 移动开发问题
9

Swift 无法使用类型为“([Score],Score)"的参数列表调用“find",其中 Sco
Swift Cannot invoke #39;find#39; with an argument list of type #39;([Score], Score)#39; where Score is a struct(Swift 无法使用类型为“([Score],Score)的参数列表调用“find,其中 Score 是一个结构)...
2024-04-15 移动开发问题
6

如何使用 UIImageViewExtension 与 Swift 异步加载图像并防止重复图像或错误图像加载到单元格
How to load image asynchronously with Swift using UIImageViewExtension and preventing duplicate images or wrong Images loaded to cells(如何使用 UIImageViewExtension 与 Swift 异步加载图像并防止重复图像或错误图像加载到单元格) - IT屋-程序员软...
2024-04-15 移动开发问题
3