Ios 导航(和状态)栏颜色与编程不同(alpha自动设置为0.85)

Ios 导航(和状态)栏颜色与编程不同(alpha自动设置为0.85),ios,swift,uikit,Ios,Swift,Uikit,目标 我正在尝试将我的导航栏涂成灰色RGB 33、33、33。问题是,当我使用颜色时,我总是得到一种更浅的颜色: UIColorred:33/256,绿色:33/256,蓝色:33/256,alpha:1 问题 所以我必须把颜色调暗到RGB 8,8,8,这样才能使用数字颜色计进行验证:得到我想要的33,33,33灰色 代码 我使用的代码如下所示: // NAV BAR let navigationBarAppearace = UINavigationBar.appearanc

目标

我正在尝试将我的导航栏涂成灰色RGB 33、33、33。问题是,当我使用颜色时,我总是得到一种更浅的颜色:

UIColorred:33/256,绿色:33/256,蓝色:33/256,alpha:1

问题

所以我必须把颜色调暗到RGB 8,8,8,这样才能使用数字颜色计进行验证:得到我想要的33,33,33灰色

代码

我使用的代码如下所示:

    //  NAV BAR
    let navigationBarAppearace =  UINavigationBar.appearance()
    navigationBarAppearace.tintColor = UIColor.white
    navigationBarAppearace.barTintColor = UIColor(red: 0.03, green: 0.03, blue:0.03, alpha: 1)
    navigationBarAppearace.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
    
    //  STATUS BAR APPEARANCE
    UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
我发现了什么

我已经研究过使用Xcode调试视图层次结构,右键单击导航栏并按“打印说明”

要获得此信息:

这意味着alpha已经设置为0.85,即使我从未显式地将其设置为该值,无论是在Interface builder中还是在代码中的任何地方

如果要使用与导航栏相同的颜色为任何其他视图着色,请使用:

UIColorred:0.03,green:0.03,blue:0.03,alpha:0.85 相当于 UIColorred:8/256,绿色:8/256,蓝色:8/256,阿尔法:0.85

相同的RGB,alpha为0.85

问题


如何删除导航栏上的0.85 alpha以在整个应用程序中使用相同的颜色值?

只需编写以下代码

navigationController.navigationBar.isTranslucent = false

只需编写以下代码

navigationController.navigationBar.isTranslucent = false

是否确保UINavigationBars isTranslucent属性设置为false?默认值为true谢谢!是的,就是这样。对于将来的读者,如果您使用的是外观代理,则在我的代码UINavigationBar.appearance.isTranslucent=false中,此文件将转换为navigationBarAppearace.isTranslucent=false。是否确保UINavigationBars isTranslucent属性设置为false?默认值为true谢谢!是的,就是这样。对于未来的读者,如果您使用的是外观代理,请在我的代码UINavigationBar.appearance.isTranslucent=false中转换为NavigationBarAppearance.isTranslucent=false谢谢!是的,就是这样。对于未来的读者,这将在我的代码中转换为navigationBarAppearace.isTranslucent=false谢谢!是的,就是这样。对于未来的读者,这将在我的代码中转换为navigationBarAppearace.isTranslucent=false