Mapbox标注附件

时间:2017-06-04 22:04:27

标签: ios swift annotations mapbox callout

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

let button = UIButton(type: .detailDisclosure)

或者,如果有快速修复将这些UIButtons转换为UIImages以创建我自己的按钮。

1 个答案:

答案 0 :(得分:1)

是的,您可以使用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
}