3
votes

I am trying to get a customized color for my apps navigation bar and it's not coming up right. The hex code for the exact color I need to use is the blue #023883. I looked up the rbg percentages from this site: http://www.colorhexa.com/023883 and the percentages are: rgb(0.8%,22%,51.4%). I put it inside my code like this:

self.navigationController.navigationBar.barTintColor = [UIColor 
colorWithRed:0.8 green:22 blue:51.4 alpha:1.0]; 

self.navigationController.navigationBar.titleTextAttributes = 
@{NSForegroundColorAttributeName : [UIColor lightGrayColor]}; 

self.navigationController.navigationBar.backgroundColor = [UIColor 
whiteColor]; 

self.navigationController.navigationBar.translucent = YES;

I also tried to implement code that enables the use of inputting hexcode for the color value but that didn't work either. Is there another way for me to be able to achieve this color? (I also tried to put only blue at 100 and it still wasnt dark enough a color)

3
r u using Storyboard - Anbu.Karthik
Yes, I am using storyboard - Christophorus
I give the Upvote , have a nice day , I also face the issue in starting , Now only in my answer easily optimize the coding and time also. - Anbu.Karthik

3 Answers

3
votes

You forget % ,it should be

 self.navigationController.navigationBar.barTintColor = [UIColor
                                                        colorWithRed:0.008 green:0.22 blue:0.514 alpha:1.0];

enter image description here

Edit,about how to make statusBar white

  1. set this key to NO in info.plist file View controller-based status bar appearance.Click the plus icon in the right of Information Property List,then you click a V in the new row,it will auto complete,the first one is this key enter image description here
  2. In app delegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [application setStatusBarStyle:UIStatusBarStyleLightContent];
    return YES;
    }
    

enter image description here

2
votes

Step-1

Select your NavigationController

Step - 2

selet the Navigation bar

enter image description here

Step-3

you can get the Navigation bar attributes

enter image description here

Step -4 in Here you can change Title , Font, Background color , etc.

enter image description here

statusBar - Transparent

Target --> Genral --> U get the following result change Status Bar Style --> Light , please follow the image.

don't forget to set NO in plist String Name is --> View controller-based status bar appearance

enter image description here

1
votes

You are using colorWithRed:green:blue:alpha wrong. You are supposed to enter percentages (0.8, 22 and 51.4 in your case), but are entering them in a wrong manner.

Please enter 0.008, 0.22 and 0.514 instead:

 self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.008 green:0.22 blue:0.514 alpha:1.0];