【问题标题】:Use BarButtonItem as leftCallOutAccessoryView for MKPinAnnotationView?使用 BarButtonItem 作为 MKPinAnnotationView 的 leftCallOutAccessoryView?
【发布时间】:2012-10-12 10:18:28
【问题描述】:

标题几乎解释了它。是否可以?我试图这样分配它:

UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveAnnotation:)];
pinView.leftCalloutAccessoryView = leftButton;

我也尝试将其转换为 UIButton 和 UIView。我想要这个的主要原因是因为我想要那个小保存按钮已经集成在 UIBarButtonSystemItemSave 中。我怎样才能做到这一点?

【问题讨论】:

    标签: iphone ios uibutton uibarbuttonitem mkpinannotationview


    【解决方案1】:

    不,这不可能,主要是因为UIBarButtonItem 不是UIView 的子类。

    将其转换为UIButtonUIView 不起作用,因为转换不会对象从一种类型转换为另一种类型。它只是让您通知编译器某些变量可以被视为其他类型(如果该变量不是真正的其他类型,您将得到一个异常或者它不起作用)。

    UIBarButtonItemUIBarItem 的子类(NSObject 的子类),仅用于UIToolbarUINavigationBar

    我不建议尝试将 UIToolbar 放在标注中只是为了使用 UIBarButtonItem
    Here's a look-alike workaround using UISegmentedControl 但分段控件在标注中也可能看起来不正确。

    我建议使用带有自定义图像或按钮类型UIButtonTypeContactAdd(带加号的蓝色圆圈)的常规UIButton

    【讨论】:

    • 我最终用 UIBUttonTypeCustom 制作了一个 UIButton,并带有一个快速制作的保存按钮的图像。谢谢。
    猜你喜欢
    • 2015-12-24
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多