UIPopoverController presentPopoverFromBarButtonItem:...偏离中心

时间:2012-03-21 15:46:42

标签: ios uikit uipopovercontroller uibarbuttonitem

我在条形按钮项目中显示一个弹出窗口,并且弹出窗口的箭头没有水平居中于该项目下方:

presenting popover from bar button item

我想让它向左移动几个像素。

一旦我使用自定义图片创建,它就不会出现在所有UIBarButtonItem个实例上。因此,例如,最右边的按钮项具有完美居中的箭头,并使用系统项进行实例化:

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

但如果我使用自定义图片,

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

......它偏离了中心。我已经尝试调整按钮项的imageInsets,但它会拉伸图像。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

原来最简单的方法是实现自己的UIPopoverBackgroundView子类,并用它来调整显示箭头的位置。这涉及很多自定义绘图代码,如果没有设计师我就无法完成它,但我们还是想要自定义背景,所以值得。

如果没有可以解决的问题,我仍然不知道如何解决这个问题。