1

I added a Navigation Bar to the .xib. I did that because I want to customize a lot of things of it. I want my navigation controller to use that navigation bar in that screen.

I created the outlet named navBar and did:

[self.navigationController.navigationBar = navBar;

But it says that navigationBar is readonly. Is it possible to link my existing navigation controller with the navigation bar that I added to the screen?

Tony
  • 10,088
  • 20
  • 85
  • 139

3 Answers3

1

It sounds to me that you may not actually want to use a UINavigationBar. As it states in the reference documentation:

The UINavigationBar class implements a control for navigating hierarchical content. It’s a bar, typically displayed at the top of the screen, containing buttons for navigating up and down a hierarchy. The primary properties are a left (back) button, a center title, and an optional right button. You can specify custom views for each of these.

So if you're planned customizations go beyond adding buttons, changing it's color / background, opacity, hiding etc.. you might be better off creating a UIView that mimics the look & feel of a navigation bar.

Here's an example of how to give your UIView that gradient look of a navigation bar.

It's far more flexible and actually quite easy to do BUT you've got alot of reading and testing ahead of you :).

Just in case if it's just buttons you're thinking of adding you might be better off using UIToolbar instead

Community
  • 1
  • 1
Judioo
  • 1,083
  • 2
  • 13
  • 20
0

You can't do that. Since the navigation controller's navigation bar has a lot of settings embedded, it's a readonly property and you shouldn't be able to change it.

What exactly are you trying to achieve that you need to do that via interface builder. I mean, with the newest APIs, it should be simple to do everything you want with a few lines of code, by customising the original navcontroller's navbar.

Bruno Koga
  • 3,864
  • 2
  • 34
  • 45
  • I want to draw the navigation bar in another position. I tried [[[self navigationController] navigationBar] setFrame:CGRectMake(6.0f, 33.0f, 308.0f, self.navigationController.navigationBar.frame.size.height)]; but it has a weird behavior. It shows a blank space at the beginning and after 1 second the navigation bar moves to that blank position. – Tony Jul 23 '12 at 19:45
  • maybe you can check when the code is called, and try to set it earlier? – Stein van Broekhoven Jan 24 '14 at 12:05
0

You would not manage a navigation bar in interface builder. Also, you would not try to set the navigationBar property of the navigation controller.

To make changes you would make changes to the navigationItem property of the navigationBar

[self.navigationController.navigationBar setItems:newNavItems];

You can also make other changes to the navigationBar such as setting a background image or making it translucent

self.navigationController.navigationBar.translucent = true;
[self.navigationController.navigationBar setBackgroundImage:img forBarMetrics:barMetrics];
James Paolantonio
  • 2,194
  • 1
  • 15
  • 32
  • How can I change its position? – Tony Jul 23 '12 at 19:59
  • You can take a look here: http://stackoverflow.com/q/4019619/1535038 but be advised Apple is not a big fan of moving the navigation bar. You may find your app getting rejected if you do not follow Apple's HIG – James Paolantonio Jul 23 '12 at 20:17