UIPopoverController presentPopoverFromBarButtonItem: ... Off-center

I am rendering a popover from a button element in a panel, and the position arrow is not horizontally centered below the element:

presenting popover from bar button item

I would like to shift it to the left a few pixels.

This does not happen on all instances UIBarButtonItem

as soon as I create with custom images. So, for example, the rightmost button element has a perfectly centered arrow, and it is created using the system element:

[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareButtonWasPressed:)]


But if I use my own image,

[[UIBarButtonItem alloc] initWithImage:slideshowImage style:UIBarButtonItemStylePlain target:self action:@selector(slideshowButtonWasPressed:)]


... it's off-center. I tried to customize the imageInsets

button element but it stretches the image. Any suggestions?


source to share

1 answer

The easiest way to do this is to implement your own subclass UIPopoverBackgroundView

and use that to customize where the arrow appears. It involved a lot of custom drawing code and I couldn't have done it without a designer, but we wanted to create our own background anyway, so it was worth it.

Still not sure how I will fix this without any reasoning.



All Articles