Here is the code that I use to insert a custom UIBarButtonItem as a leftButton on my navigator. The problem is that the button is too close to the left edge, and I canβt understand how to step back a little from it without using another image with an addition on the left?
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
btn.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
[btn setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
self.myBtn = btn;
[btn release];
UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:self.myBtn];
self.myBarBtn = barBtn;
self.myBarBtn.imageInsets = UIEdgeInsetsMake(0, 5, 0, 0);
[self.navigationItem setLeftBarButtonItem:self.myBarBtn animated:YES];
[barBtn release];
I tried setting up the frame, edgeInsets, all with no luck. BarButtonItem is still too close to the left. Is there a way to offset the image for the button?
thank
James source
share