I am trying to change the color of my navigation bar. The following rgb is for a dark red color, but my nav bar turns white after the following code.
navigationController.navigationBar.tintColor = [UIColor colorWithRed:117 green:4 blue:32 alpha:1];
Let's see how to change the background color of a navigation bar through the storyboard editor. Create a new project, select it's view controller and embed in navigation controller. Select the navigation bar and go to It's attribute inspector.
A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.
This is because the CGFloat
values range from 0.0 to 1.0
not from 0 to 255
, and values above 1.0
are interpreted as 1.0
.
Here is the documentation:UIColor
Just do this:
navigationController.navigationBar.tintColor = [UIColor colorWithRed:117/255.0f green:4/255.0f blue:32/255.0f alpha:1];
You have to divide each value for 255. Try:
[UIColor colorWithRed:117/255.0f green:4/255.0f blue:32/255.0f alpha:1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With