2016-06-22 5 views
0

Ich verwende MKPinAnnotationView in meiner App.Annotation Title und SubTitle in Custom MKPinAnnotationView anzeigen

Ich gründe MapView Objekt als Delegierter, und mit diesem Code für meine Anpassung AnnotationView

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

     if annotation is MKUserLocation { 
      //return nil so map view draws "blue dot" for standard user location 
      return nil 
     } 

     let reuseId = "pin" 

     var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView 
     if pinView == nil { 
      pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 
      // pinView!.canShowCallout = true 
      pinView!.image = UIImage(named:"store.jpg") 
      pinView!.animatesDrop = true 
      pinView!.pinTintColor = UIColor.darkGrayColor() 
     } 
     else { 
      pinView!.annotation = annotation 
     } 

     return pinView 
    } 

Ich erhalte benutzerdefinierte AnnotationView wie ich required.However, mir fehlt die Eigenschaften title und subtitle von MKPointAnnotation.

Ich möchte Titel und Untertitel für die grauen Punkte sehen. enter image description here

Antwort

0

ich deshalb überwiegend wäre eine func

func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) { 
     mapView.deselectAnnotation(view.annotation, animated: true) 
    } 

ich diese Funktion aus kommentiert und bekam den Titel und Untertitel.

Aktualisiert-Code

/* 
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) { 
mapView.deselectAnnotation(view.annotation, animated: true) 
} 
*/ 
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 

    if annotation is MKUserLocation { 
     //return nil so map view draws "blue dot" for standard user location 
     return nil 
    } 

    let reuseId = "pin" 
    let pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 
    pinView.canShowCallout = true 
    pinView.animatesDrop = true 
    pinView.pinTintColor = UIColor.darkGrayColor() 
    pinView.draggable = true 
    pinView.accessibilityLabel = "hello" 
    let btn = UIButton(type: .DetailDisclosure) 
    pinView.rightCalloutAccessoryView = btn 
    return pinView 
} 
Verwandte Themen