2016-09-22 2 views
0

Ich versuche, meinen zwei MKPointAnnotation-Pins ein benutzerdefiniertes Bild zu geben. Bis jetzt bin ich in der Lage, das gleiche Bild auf beiden Stiften anzuzeigen. Was kann ich mit dem unten stehenden Code tun, um jedem Pin ein benutzerdefiniertes Image zu geben?Mehrere benutzerdefinierte Punkt-Anmerkungen - Swift

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 

     guard !(annotation is MKUserLocation) else { 
      return nil 
     } 


     let annotationIdentifier = "AnnotationIdentifier" 

     var annotationView: MKAnnotationView? 

     if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) { 
      annotationView = dequeuedAnnotationView 
      annotationView?.annotation = annotation 
     } 
     else { 
      annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier) 
      annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure) 
     } 


     if let annotationView = annotationView { 
      annotationView.canShowCallout = true 
      annotationView.image = UIImage(named: "Moto_pin") 
     } 

     return annotationView 
    } 

Antwort

0

Statt annotationView.image = UIImage(named: "Moto_pin"), möchten Sie das Bild für jeden Stift ändern. Diese Zeile weist jeder Anmerkungsansicht dasselbe Bild zu.

+0

Aber wie greife ich auf die examplePoint = MKPointAnnotation() Bild? – cosmos

0

Versuchen Sie, MKPinAnnotationView anstelle von MKAnnotationView zu verwenden. Um dies zu tun, müssen Sie nur ändern:

var annotationAnsicht: MKPinAnnotationView?

Mit dieser Klasse, die Sie Ihre PIN-Farbe und der ganzen Ansicht

+0

Ich versuche ein Bild zu verwenden, um den Pin nicht zu färben. – cosmos

Verwandte Themen