Well, I finally found myself a solution:
I had a UIBarButtonItem
with UIBarButtonItemStylePlain
and an image setted with setImage
on the UIBarButtonItem
.
To solve the issue, I have created an UIButton
with the image (setting its frame with an CGRectMake
) , and then I have created the UIBarButtonItem
with initWithCustomView
and using the UIButton
as the CustomView
. This way the image is always where it should be.
Edit:
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButton.frame = CGRectMake(0.0, 40.0, 30.0, 30.0);
[aButton setBackgroundImage:[UIImage imageNamed:@"anImage.png"] forState:UIControlStateNormal];
[aButton addTarget:self action:@selector(aFunction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *anUIBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:aButton];
self.navigationItem.rightBarButtonItem = anUIBarButtonItem;