0
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    guard annotation is MKPointAnnotation else { return nil }

    let identifier = "Annotation"
    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)

    if annotationView == nil {
        annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
        annotationView!.canShowCallout = true
        annotationView!.pinTintColor = UIColor.redColor
    } else {
        annotationView!.annotation = annotation

    }

    return annotationView
}

为什么我有错误“'MKAnnotationView' 类型的值没有成员'pinTintColor'”?我想在不改变图像的情况下将别针的颜色从橙色更改为蓝色。我使用 swift 5.2 和 xcode 11.4.1

4

1 回答 1

1

从编译器的角度来看,annotationView是 a MKAnnotationView?,仅此而已。您可以像这样重写您的支票:

if annotationView == nil {
    let pin = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
    pin.canShowCallout = true 
    pin.pinTintColor = UIColor.redColor
    annotationView = pin
}
于 2020-05-22T12:12:47.117 回答