色调颜色使用原生颜色,但不适用于图案图像的颜色

时间:2018-06-07 08:16:01

标签: ios swift tint bartintcolor

当我使用原生颜色时,我使用导航栏色调颜色命名导航栏后退按钮,当我使用图像中的自定义颜色时,它会失败。

工作代码:

self.navigationController?.navigationBar.tintColor = UIColor.orange

不工作代码:

let color = UIColor.init(patternImage: someImage)
self.navigationController?.navigationBar.tintColor = color

有人能表现出一些亮点吗?

2 个答案:

答案 0 :(得分:2)

您不能将图案颜色用作色调颜色。

请参考以下链接: https://developer.apple.com/documentation/uikit/uiview/1622467-tintcolor

查找此注释:

  

重要

     

如果您尝试将图案颜色用作色彩,系统   引发异常。

答案 1 :(得分:0)

如果您有图像,请将导航栏中的图像设置为背景图像。喜欢:

self.navigationController?.navigationBar.setBackgroundImage(#imageLiteral(resourceName: "NavigationBackground"), for: .default)

希望这有用。