Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the toolbar color of the Navigation Controller in iOS?

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];
like image 302
aryaxt Avatar asked Aug 24 '11 17:08

aryaxt


People also ask

How do I change the color of the navigation bar in IOS Swift?

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.

How do I change the navigation bar on my Iphone?

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.


3 Answers

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

like image 100
Oscar Gomez Avatar answered Oct 09 '22 09:10

Oscar Gomez


Just do this:

navigationController.navigationBar.tintColor = [UIColor colorWithRed:117/255.0f green:4/255.0f blue:32/255.0f alpha:1];
like image 16
TommyG Avatar answered Oct 09 '22 07:10

TommyG


You have to divide each value for 255. Try:

[UIColor colorWithRed:117/255.0f green:4/255.0f blue:32/255.0f alpha:1]
like image 6
fncap Avatar answered Oct 09 '22 08:10

fncap