Well, finally, I found a solution:
I had UIBarButtonItemwith UIBarButtonItemStylePlainand the image configured using setImageon UIBarButtonItem.
To solve the problem, I created UIButtonwith the image (setting its frame to CGRectMake), and then created UIBarButtonItemwith initWithCustomViewand using UIButtonas CustomView. Thus, the image will always be 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;
source
share