0

i have this piece of code which permits me to insert a title on the UIbar (if i'm not wrong) of the app.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ApplicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToAlbum) name:@"GetAlbumNotif" object:nil];
self.title = @"Events List";

Can you please give me an orientation to this? Thanks!

Lucas
  • 6,675
  • 3
  • 25
  • 43
Alb
  • 45
  • 7
  • 1
    Do you want to add an image to the center of the navigationBar? Do you want to add a UIBarButton with an image inside? Please give some more information! –  Aug 23 '12 at 21:18
  • I need to add an image to the center of the navigation bar please! – Alb Aug 23 '12 at 21:25

2 Answers2

1
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage"]];
self.navigationItem.titleView = imageView;
  • Now i may sound dumb but i have no other choice, it is supposed to work just by copy-pasting this code? am i suppose to declare anything else elsewhere? – Alb Aug 23 '12 at 21:35
  • just replace `self.title = @"Events List";` with my code and change it to the right image name. And you should start reading some of the Apple documentations before you ask to many questions here! –  Aug 23 '12 at 21:39
  • Thank you, you're right i should start reading, i have indeed, but hey i tried this code, and it won't display the image there.. – Alb Aug 23 '12 at 21:45
  • there is something like a breakpoint, there is a button, a reload button on the bar.. – Alb Aug 23 '12 at 21:45
0

A UIBarButton is inside a NavigationBar. The easiest way is to add a UIBarButton to the NavigationBar in the Interface Builder. After that, you can alter the background with:

[barButton setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

You can change the appearance of a navigation bar if your deployment target is iOS 5.0 or higher with :

[UINavigationBar appearance] setBackgroundImage:

Or do the old fashion way with subclassing UINavigationBar and override drawInRect. How to do that can be found here: How to add background image on iphone Navigation bar?

Community
  • 1
  • 1
zeiteisen
  • 7,078
  • 5
  • 50
  • 68