Custom barTintColor for navigationBar

I'm trying to get a custom color for the app navigation bar and it doesn't work. The hex code for the exact color I need is blue # 023883. I looked at the rbg percentages from this site: http://www.colorhexa.com/023883 and the percentages: rgb (0.8%, 22%, 51, 4%). I put it in 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 a code that allows hexadecimal input for the color value, but that didn't work either. Is there any other way for me to achieve this color? (I also tried putting only blue at 100 and it still wasn't dark enough)

+3


source to share


3 answers


You forgot%, it must be

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

      

enter image description here



Edit, on how to make the statusBar white

  • set this key to NO in info.plist file View controller-based status bar appearance

    . Click the icon to the plus

    right of the Property Information List , then click the button V

    in a new line, it will auto complete, this key will be the first enter image description here
  • In the application

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

enter image description here

+3


source


Step 1

Please select NavigationController

Step - 2

divide Navigation bar

enter image description here

Step 3

you can get navbar attributes



enter image description here

Step -4 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

to plist

String name ->View controller-based status bar appearance

enter image description here

+2


source


You are using it colorWithRed:green:blue:alpha

wrong. You must enter percentages (0.8, 22, and 51.4 in your case), but you are entering them incorrectly.

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]; 

      

+1


source







All Articles