Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change background color of UINavigationItem?

I have a UINavigationItem, but I can't found anything beside tittle, prompt, and back button in attribute inspector

enter image description here

I wonder how can I change my UINavigationItem background color using code? or programmatically?

like image 951
Ega Setya Putra Avatar asked May 11 '15 02:05

Ega Setya Putra


People also ask

How do I change the background on my navigation bar?

In order to change the hub navigation bar color, we can go to site settings of hub site>Change the look>under the header section>Background> select a theme color to change the background color of your site header.

How do I change the background color in swift navigation?

navigationController. navigationBar. barTintColor = UIColor. newBlueColor() and of course this just changes the colour of the navigation bar of the view controller that the code is within.


1 Answers

You can change it through code...

For Objective-C:

    self.navigationController.navigationBar.barTintColor = [UIColor redColor];

Write Above line in viewDidLoad method.

For Swift:

    self.navigationController?.navigationBar.barStyle = UIBarStyle.BlackTranslucent

    self.navigationController?.navigationBar.barTintColor  = UIColor.redColor();

OR

    self.navigationController!.navigationBar .setBackgroundImage(UIImage .new(), forBarMetrics: UIBarMetrics.Default)
    self.navigationController!.navigationBar.shadowImage = UIImage .new();
    self.navigationController!.navigationBar.translucent = true;
    self.navigationController!.navigationBar.backgroundColor = UIColor.redColor();

You can change color on your own choice.

To change the bar Text...

navigationController.navigationBar.titleTextAttributes = [UITextAttributeTextColor: UIColor.blueColor()]

See the Link.... Here

enter image description here

See the above image... you like output like this screen right...!!!

like image 148
Ashok Londhe Avatar answered Oct 07 '22 16:10

Ashok Londhe