2
votes

I need to customize UIBarButtonItem back button so it is displayed with a simple arrow icon (like in Facebook, Twitter etc). Do I need to create a custom UIBarButtonItem and manually add it to the nav bar or is there a way to do this through appearance API?

Thanks

2

2 Answers

4
votes

You have to make your own and add it

You can do it like this (this is for a custom button using an image)

UIImage* image3 = [UIImage imageNamed:@"favorites.png"];
    CGRect frameimg = CGRectMake(0, 0, image3.size.width, image3.size.height);

    UIButton *someButton2 = [[UIButton alloc] initWithFrame:frameimg];
    [someButton2 setBackgroundImage:image3 forState:UIControlStateNormal];
    [someButton2 addTarget:self action:@selector(loadFavorites)
          forControlEvents:UIControlEventTouchUpInside];
    [someButton2 setShowsTouchWhenHighlighted:YES];

    UIBarButtonItem *favoritesButton =[[UIBarButtonItem alloc] initWithCustomView:someButton2];

    self.navigationItem.rightBarButtonItems =[NSArray arrayWithObjects:favoritesButton, nil];
0
votes

Okay so it turns out that you can't actually use backBarButtonItem with a UIBarButtonItem created with a custom view. The best I can offer is you can create a template with an image and a empty background image, although it feels a bit like spacer.gif. I threw together a quick example to show what I meant about the view controller ordering too.

http://cl.ly/36091p0l0120