5

I am setting self.navigationItem.rightBarButtonItem = self.editButtonItem; in viewDidLoad this works perfect in iOS < 7 in 7 I get below, why isn't title centered? What am I doing wrong?

enter image description here

Also when there is a back button and it has not been clicked at least once I get: enter image description here

After it is clicked I get: enter image description here

The background of buttons is set in app delegate:

    // Change the appearance of back button
UIImage *backButtonImage = [[UIImage imageNamed:@"backbtn"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 6)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

// Change the appearance of other navigation button

UIImage *barButtonImage = [[UIImage imageNamed:@"btn"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
[[UIBarButtonItem appearance] setBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Simon M
  • 2,931
  • 2
  • 22
  • 37
kos
  • 1,357
  • 9
  • 21
  • You should add that as an answer and mark it or delete the question. – Wain Oct 03 '13 at 16:07
  • Unfortunately I am not clear if I should not be doing this in iOS 7? Am I not supposed to use background images for buttons and barbuttons ? Should I be able to do this? Also I am not able to mark it as an answer. – kos Oct 08 '13 at 23:51
  • have u centered the title for right bar button..If so how u achieved this – Sandeep Oct 11 '13 at 14:14
  • Nope, still an issue. Still would like to know how to resolve this. I think there is similar issue when replacing accessory image with a button in a table cell, but this could be unrelated. – kos Oct 17 '13 at 02:19
  • Got the same issue -_- I'll post an answer if find any solution – eagle.dan.1349 Oct 17 '13 at 07:53

1 Answers1

0

Had the same problem with navigation under iOS7...

Got several answers here and there but they don't appear to be helpful. If you use backIndicatorImage of UINavigationBar it sticks to the top and I don't know how to fix it.

I ended up doing what is suggested here

Create a UIBarButtonItem like this:

UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                                            style:UIBarButtonItemStylePlain
                                                           target:self
                                                           action:@selector(backButtonAction:)];

backBackgroundImage = [UIImage imageNamed: @"back_btn"];
backBackgroundImage = [backBarButtonBackground resizableImageWithCapInsets:
                                                          UIEdgeInsetsMake(0.0, 14.0, 0.0, 5.0)];
[backBtn setBackgroundImage:backBackgroundImage
                   forState:UIControlStateNormal
                 barMetrics:UIBarMetricsDefault];

[backBtn setTitlePositionAdjustment:UIOffsetMake(5, 0) forBarMetrics:UIBarMetricsDefault];

And then use it as the back button on your navigation controller.

Community
  • 1
  • 1
eagle.dan.1349
  • 611
  • 1
  • 8
  • 20
  • 1
    This may or may not work depending on where it is done, I was trying to set navigation item buttons in app delegate so that they are reused everywhere. So I am not sure that setting offset for title would work, but will give it a try. For now I removed the use of images all together. This also may not solve the problem where image is not displayed the first time it is to be used on navigation bar. – kos Oct 20 '13 at 18:00
  • Yes, you're right. But as you can see, iOS7 just forses you to do it on each of your ViewControllers. Also notice the following strange thing: system controllers (ex. MFMailComposeViewController) will set font of YOUR leftBarButtonItem when presented modally, so beware of that thing. Not shure if it will ever get documented. – eagle.dan.1349 Oct 21 '13 at 06:50
  • Also, I got the same thing with edit button. And I had to replace it with a custom one too. – eagle.dan.1349 Oct 22 '13 at 06:40