1

I embeded in a navigation controller to a viewController, and a nav bar item is showing (in the outline editor), and I can change the title, but the navigation bar is not showing in the (outline editor) and I therefore cannot change the bar tint color. So I tried adding in a nav bar programmatically, like this:

.h file

@property (strong, nonatomic) UINavigationBar *nav;

.m file

nav = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
self.nav.tintColor = [UIColor blueColor];
[self.view addSubview:nav];

And here is the outcome:

enter image description here

Update

enter image description here

Horray
  • 693
  • 10
  • 25

3 Answers3

2

Your last comment in above answer that "I made the color to blue, and it shows it blue in the storyboard" is conflict here.

I guess you are not able to set tint color for navigation bar. Because Storyboard won't show any color tint color for navigation bar, it's only visible at run time (In Simulator).

Even if you change tint color of navigation bar it still shows white color.

Lets have a look:

  1. As "matt" said : You have to change bar tint color of UINavigationController which is starting point of your application. Select navigation controller which is initial root view controller.

enter image description here

  1. Select Navigation Bar from left area below the highlighted Navigation Controller. In Attribute Inspector you can see properties for navigation bar. In this section you can see Bar Tint which shows Default right now.

enter image description here

  1. Change Bar Tint color from properties as your need. Observation here is changes will not be visible in Storyboard, Bar color will remains white in Storyboard color will only visible in Simulator/Device.

enter image description here

  1. See the output in Simulator.

enter image description here

Kampai
  • 22,848
  • 21
  • 95
  • 95
1

Don't do that. Delete that code. The navigation controller already has a navigation bar; don't add another one.

You're looking in the wrong scene. There's a Navigation Controller scene and a View Controller scene. The navigation bar belongs to the Navigation Controller scene.

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • So I changed the color of the viewController to white. (It was clear before, I guess I didn't realize it.) Then I deleted the code, and I made the navigation bar to blue, and the navigation bar's color is still the same as shown the the picture above? – Horray Dec 22 '14 at 21:36
  • The color is not changing correctly. I think it is because I made a new navigatoinBar programmatically. Do you know a way to fix it? – Horray Dec 22 '14 at 23:58
  • Well, I told you in my answer to delete the code that makes a new navigation bar, didn't I? If you don't do what my advice says, my advice won't work, will it? – matt Dec 23 '14 at 00:16
  • I deleted it and now its outputting it as shown in my update. I made the color to blue, and it shows it blue in the storyboard, but when I run it on the simulator, it shows it like the picture above – Horray Dec 23 '14 at 00:22
0

I was using the viewController that is flexible for the ipad and iphone. Now in that viewController I inserted a navigation controller for each viewController. (Which surprisingly xcode lets you do that. And at the time I didn't know it was wrong.) So I set the bar tint color at the navigation controller that was not the first one. (It was the second view navigation controller) It therefore had a conflict of which color to take, the color from the first navigation controller, or the current navigation controller.

Horray
  • 693
  • 10
  • 25