1

I have three left bar button items on my web view nav bar. One that goes back to the the menu of my app and back and forward buttons. I have one right bar button that opens an activity view controller. When I press the right button, the forward and back buttons on the left get moved down and off of the nav bar.

- (void)viewDidLoad
{   
    leftBarButtonItems = [NSArray arrayWithObjects:@"Menu", @"Back", @"Forward", nil];

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSString *urlAddress = @"http://www.littleheartrecords.com/releases.html";
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];

    UIBarButtonItem *systemAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showMenu)];
    self.navigationItem.rightBarButtonItem = systemAction;

    UIBarButtonItem *openItem = [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStylePlain target:self action:@selector(openButtonPressed)];
    self.navigationItem.leftBarButtonItem = openItem;

    UIImage *back = [UIImage imageNamed:@"back_arrow"];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithTitle:@"" style: UIBarButtonItemStylePlain target:self action:@selector(GoBack)];
    [backButton setImage:back];

    UIImage *forward = [UIImage imageNamed:@"forward_arrow"];
    UIBarButtonItem *forwardButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:@selector(GoForward)];
    [forwardButton setImage:forward];

    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:openItem, backButton, forwardButton, nil];
}

enter image description here enter image description hereenter image description here

memmons
  • 40,222
  • 21
  • 149
  • 183
raginggoat
  • 3,570
  • 10
  • 48
  • 108
  • Where is "setImage:" documented? UIBarButtons have a "setBackgroundImage:forState:barMetrics:". – Charlie Price Jan 23 '14 at 16:18
  • If you set a background image with "setBackgroundImage:forState:barMetrics:" the image appears below the nav bar to start? I get different results for iOS 6, have you tried that to see what happens? – Charlie Price Jan 23 '14 at 16:28
  • Using setBackgroundImage: makes the images not look right and they start below the nav bar. – raginggoat Jan 23 '14 at 16:44

1 Answers1

3

Strangely, what worked for me was setting the title of the buttons with images to a single space:

barButtonItem.title = @" ";
barButtonItem.image = [UIImage imageNamed:@"MenuIcon.png"];
J-DawG
  • 1,035
  • 9
  • 24