Q:

on iOS, how can I shift navigationItem.leftBarButtonItem horizontally right?

A cusomized UINavigationBar requires me to present a customized "back" button, I use navigationItem.leftBarButtonItem = myCustomizedButton, but its position is fixed.
Would anyone be so kind to share how can I shift this button 40pixels to right?

A:

You can create a containing view that is 40 pixels bigger than your image.
Add your image at 40 pixels offset.
Add the containing view as the leftBarButtonItem.
Code follows:
// Create a containing view to position the button
UIView *containingView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, barButtonImage.size.width + 40, barButtonImage.size.height)] autorelease];

// Create a custom button with the image
UIButton *barUIButton = [UIButton buttonWithType:UIButtonTypeCustom];
[barUIButton setImage:barButtonImage forState:UIControlStateNormal];
barUIButton.frame = CGRectMake(40, 0, barButtonImage.size.width, barButtonImage.size.height);
[barUIButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

[containingView addSubview:barUIButton];

// Create a container bar button
UIBarButtonItem *containingBarButton = [[[UIBarButtonItem alloc] initWithCustomView:containingView] autorelease];

// Add the container bar button
navigationItem.leftBarButtonItem = containingBarButton;

