Mapbox 标注配件

Mapbox Callout Accessory

我想知道 Mapbox 是否还有其他标注按钮,而不仅仅是提供的七个按钮?

let button = UIButton(type: .detailDisclosure)

或者如果有一个快速修复方法可以将这些 UIButton 转换为 UIImage 以创建我自己的按钮。

是的,您可以使用方法 func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView?func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? 创建您自己的。将按钮类型设置为 .custom

例如:

func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
    // We're not concerned with the user annotation.
    guard annotation is CameraAnnotation || annotation is NoteAnnotation else {
        return nil
    }
    // Callout height is fixed; width expands to fit its content.
    let deleteButton = UIButton(type: .custom)
    deleteButton.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
    deleteButton.setImage(UIImage(named: "delete"), for: .normal)
    deleteButton.tag = 100
    return deleteButton
}