ios - UIPopoverController presentPopoverFromBarButtonItem :. .. 偏心

标签 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,但它拉伸(stretch)了图像。有什么建议吗?

最佳答案

事实证明,最简单的方法是实现您自己的 UIPopoverBackgroundView 子类,并使用它来调整显示箭头的位置。这涉及到很多自定义绘图代码,没有设计师我无法完成,但无论如何我们都想要一个自定义背景,所以这是值得的。

如果没有有争议的变通办法,我仍然不知道如何解决这个问题。

关于ios - UIPopoverController presentPopoverFromBarButtonItem :. .. 偏心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9808081/

相关文章:

ios - 如何在 swift 3 中访问我现有的 SQLite 数据库

swift - 支持不同 SwiftUI View 类型的 UIHostingController 数组

ios - 如何在 swift 中将 popoverview 居中

iphone - UITableViewCell 上的 UIPopoverController

iphone - UITextField - 返回 BOOL 的代表崩溃

iphone - 无法阻止 AVAudioPlayer 播放

ios - 如何在 UICollectionViewCell 中缩放 UIScrollView?

ios - 隐藏 UITableView 页脚

iphone - UIPopoverController 前面的 UIImageView

ios - webview 在 swift 3 中打开 native fb 应用程序?