I would like to set the background color of a menu to that of the navigation bar. What is the best way to do this?
Asked
Active
Viewed 2.5k times
8 Answers
40
The default navbar color in iOS 7 is [UIColor colorWithRed:(247.0f/255.0f) green:(247.0f/255.0f) blue:(247.0f/255.0f) alpha:1];

Michał Miszczyszyn
- 11,835
- 2
- 35
- 53

Nikos M.
- 13,685
- 4
- 47
- 61
-
1Do you mean : [UIColor colorWithRed:(247.0f/255) green:(247.0f/255) blue:(247.0f/255) alpha:1] – gran_profaci Jul 14 '14 at 22:23
-
2@gran_profaci there is no difference between your code and my code ;-) f just tells the compiler that this number is a float. – Nikos M. Jul 15 '14 at 04:58
-
Can you explain how do you know it ? – lapin Dec 02 '14 at 08:31
-
1@lapin Just take a screenshot and found it with color picker in Photoshop. :-) – Nikos M. Dec 02 '14 at 09:28
-
Since `colorWithRed:green:blue:alpha:` expects floats it should be `255.0f` instead of `255.0`. The later one is double and results in a compiler warning because of implicit casting. `[UIColor colorWithRed:(247.0f/255.0f) green:(247.0f/255.0f) blue:(247.0f/255.0f) alpha:1];` – Michał Miszczyszyn Jul 15 '15 at 10:13
-
13Is there any way to get this programmatically in case Apple decides to change this in the future? – Ken M. Haggerty Apr 22 '16 at 13:39
6
Swift 5
Nav bar color in light appearance:
UIColor(red: 0.969, green: 0.969, blue: 0.969, alpha: 1.0)

Jayden Irwin
- 921
- 9
- 14
4
To get the tint color of a navigation bar, do this:
[aNavbar barTintColor]
By using this when you set the background color of your menu, you will not have to change it in case you change your navigation bar tint.

Daniel Larsson
- 6,278
- 5
- 44
- 82
3
Swift 4
I am not sure the color does not change from version to version. In my app I use this:
var navBarDefaultColor: UIColor?
// save:
navBarDefaultColor = self.navigationController?.navigationBar.tintColor
//restore:
self.navigationController?.navigationBar.tintColor = navBarDefaultColor!

Diego Carrera
- 2,245
- 1
- 13
- 16

Alex
- 751
- 1
- 9
- 28
1
In Swift, it is:
UIColor(colorLiteralRed: (247/255), green: (247/255), blue: (247/255), alpha: 1)

He Yifei 何一非
- 2,592
- 4
- 38
- 69
1
Swift 3.0 +
UIColor(red: (247/255), green: (247/255), blue: (247/255), alpha: 1)

Starchand
- 684
- 1
- 9
- 23
0
You can set the barTintColor
to nil
to restore to the default white color.

funkenstrahlen
- 3,032
- 2
- 28
- 40
0
Swift 5: UINavigationBar Default barTintColor for Light Mode.
#colorLiteral(red: 0.9763854146, green: 0.9765252471, blue: 0.9763546586, alpha: 1)

ZAFAR007
- 3,049
- 1
- 34
- 45