Move UIBarButtonItem few pixels down?

I have created a custom UINavigationBar which is a tiny bit taller than Apples default navigation bar.

I can’t seem to find a way to move the UIBarButtonItem down to be directly centered between the two dashed lines.

Is there an easy way to do this? I’ve tried creating a custom button but had no success. Ideally I would just like to move the default back button down a couple of pixels.

Code used to create UINavigationBar, custom header image and UIBarButtonItem:

    //Create image for navigation background
UIImage *NavigationPortraitBackground = [[UIImage imageNamed:@"navbackground.png"]
                                         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage: NavigationPortraitBackground
                                   forBarMetrics:UIBarMetricsDefault];

//Centered title image
UIImageView *headerImage = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"hometitle.png"]];
    [headerImage setFrame: CGRectMake(0, 0, 180, 49)];
self.navigationItem.titleView = headerImage;

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] init];
[backBarButtonItem setTintColor: [UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1]];
[backBarButtonItem setStyle: UIBarButtonItemStylePlain];
    self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];

Thanks in advance,

Answers


Create the UIBarButtonItem using a custom view. This custom view will be a UIView with the actual UIButton (as a subview) placed x pixels from the top (x=the number of pixels you want to move it down).


sorry

UIButton *myButton1 = [UIButton buttonWithType:UIButtonTypeCustom];  
 [myButton1 setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];   myButton1.showsTouchWhenHighlighted = YES;  
 myButton1.frame = CGRectMake(0.0, 3.0, 50,30);  
  [myButton1 addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:myButton1];    
 self.navigationItem.leftBarButtonItem = leftButton;

Need Your Help

Conditionally Showing Graphs

excel vba

I have a bunch of graphs on a single sheet. Also, I have a drop down menu of items. When I choose a particular item, I want to only show the graph associated with that item. How would I do this?

jquery clickling fast

javascript jquery performance click

I have this function, that adds 31px to my style bottom on ul.