kmn
kmn

Reputation: 2655

Navigation (and status) bar colors different than programmed (alpha automatically set to 0.85)

The objective

I'm trying to color my navigation bar grey (RGB 33, 33, 33). The problem is, I always get a much lighter color when I use the color :

UIColor(red: 33/256, green: 33/256, blue: 33/256, alpha: 1)

The problem

So I've had to darken the color to RGB 8,8,8 for this to work (Verified using the digital color meter: getting the (33,33,33) grey I want).

The code

The code I'm using to do this is copie below:

    //  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

What I've found

I've investigated using the Xcode debug view hierarchy, right clicking on the nav-bar and pressing 'print description'

enter image description here

to get this :

<_UIVisualEffectSubview: 0x15422d1c0; frame = (0 0; 375 64); alpha = 0.85; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x1d4224c60>>

Meaning the alpha is already set to 0.85 (even though i never explicitly set it to that value), whether in Interface builder or anywhere in code.

If I want to color any other view with the same color as the navigation bar, I use :

UIColor(red: 0.03, green: 0.03, blue: 0.03, alpha: 0.85) equivalent to UIColor(red: 8/256, green: 8/256, blue: 8/256, alpha: 0.85)

(same RGB with an alpha of 0.85)

The question

How can I remove the 0.85 alpha on the navigation bar to use the same color values throughout my app ?

Upvotes: 2

Views: 364

Answers (1)

Parth Dhorda
Parth Dhorda

Reputation: 722

Just write the following code

navigationController.navigationBar.isTranslucent = false

Upvotes: 6

Related Questions