0

How do i add a small image on a UINavigationBar ? It should display in front of the title. Its small and 40X40 pixel in size.

noteL: I don't want to add an image to the background to add this tiny image. Furthermore this should work for both iOS4 and 5

Illep
  • 16,375
  • 46
  • 171
  • 302

1 Answers1

1

On a Navigation bar you can set both right and left buttons like this:

UIImage * myIcon = [UIImage imageNamed:@"icon.png"];

[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithImage:myIcon
    style:UIBarButtonItemStyleBordered target:self action:@selector(someAction:)]];

To the right button just message setRightBarButtonItem

Andre Cytryn
  • 2,506
  • 4
  • 28
  • 43
  • I would only need an image, not a button. – Illep Feb 13 '12 at 23:57
  • How could i add an image to the back button of the navigation bar ? – Illep Feb 14 '12 at 00:48
  • Then this should work: self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:yourImg style:UIBarButtonItemStyleBordered target:target action:@selector(someAction:) ]; – Andre Cytryn Feb 14 '12 at 19:49