I want to use a logo as the title of a UINavigationBar globally across all screens in my application. How can I access the navigation bar in AppDelegate?
3 Answers
If you want to affect the whole app you should use appearance proxy in AppDelegate. Something like this should do it:
let navBar = UINavigationBar.appearance()
navBar.setBackgroundImage(UIImage(named: "yourImageName"), forBarMetrics: .Default)

- 2,886
- 3
- 17
- 17
This is what i have used
add below code in App-delegate's didFinishLaunchingWithOptions method
UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image_name_here"]];
[imgView setFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2,2,70,14)];
[imgView setCenter:CGPointMake(self.view.center.x,20)];
[self.navigationController.navigationBar addSubview:imgView];
or alternate way is
UIImage *image = [UIImage imageNamed:@"image_name_here"];
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:image];

- 35,607
- 26
- 136
- 135
This is impossible. The titleView
is always local to a UIViewController
.
However, you can:
Create a subclass of
UIViewController
that will set yourself.navigationItem.titleView
to that image view and then inherit all your view controllers from this class.Create a subclass of
UINavigationController
, giving it a custom navigation bar which will always have the logo displayed inside. Then you will have to use this customized navigation controller instead ofUINavigationController
.Set it as navigation bar background image. You can actually make it globally but sometimes it's not an option (especially if you want to keep the default navigation bar appearance).
Of course, if you are using storyboads/xib, you can just put the same UIImageView
with the logo everywhere.

- 128,090
- 22
- 218
- 270