2

Back UIBarButtonItem with navigation bar title

code 1 :

UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                                              style:UIBarButtonItemStylePlain
                                                             target:self action:@selector(exits)];
    //[item setBackgroundVerticalPositionAdjustment:10.0f forBarMetrics:UIBarMetricsDefault];
    self.navBar.topItem.leftBarButtonItem = item;
    [[UIBarButtonItem appearance] setBackgroundVerticalPositionAdjustment:+5 forBarMetrics:UIBarMetricsDefault];

code 2:

UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                                              style:UIBarButtonItemStylePlain
                                                             target:self action:@selector(exits)];
    //[item setBackgroundVerticalPositionAdjustment:10.0f forBarMetrics:UIBarMetricsDefault];
    self.navBar.topItem.leftBarButtonItem = item;
    [[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, 50) forBarMetrics:UIBarMetricsDefault];

I tried both the above code this did not work

What i want to do is get back UIBarButtonItem move down in level of My Example title. How to do it.

Naresh
  • 433
  • 2
  • 15

3 Answers3

0

It looks like the problem isn't with your UIBarButtonItem, but with the placement of your entire UINavigationBar. Your UINavigationBar should be moved down by 20 pixels to account for the Status Bar. Make the changes written in this Stack Overflow question and everything should line up nicely.

Community
  • 1
  • 1
hgwhittle
  • 9,316
  • 6
  • 48
  • 60
0

If you just want to move the text down you can use…

[[UIBarButtonItem appearance] 
       setBackButtonTitlePositionAdjustment:UIOffsetMake(0, 6) 
                              forBarMetrics:UIBarMetricsDefault];
Onato
  • 9,916
  • 5
  • 46
  • 54
-1

Sorry for late answer. If you are still looking for answer, try the following. It worked for me:

item.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
item.contentEdgeInsets = UIEdgeInsetsMake(2.0, 0.0, 0.0, 0.0);
SasaT
  • 731
  • 6
  • 19
  • 1
    XCode 5.1.1 doesn't appear to accept this. Are there any library imports needed to access 'contentVerticalAlignment' and 'contentEdgeInsets' ? – Timothy Swan Aug 11 '14 at 02:55