2016-06-22 5 views
0

私はMKPinAnnotationViewを私のアプリケーション内で使用しています。カスタムMKPinAnnotationViewで注釈のタイトルとサブタイトルを表示

私は私required.Howeverとしての私の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 
    } 

私は取得していますカスタムAnnotationViewをカスタマイズするためのデリゲートとしてMapViewオブジェクトを設定し、このコードを使用しています、私はtitleMKPointAnnotationsubtitleの機能が不足しています。

灰色の点のタイトルとサブタイトルが表示されます。 enter image description here

答えて

0

私は1 FUNC

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

をオーバーライドして、私はこの関数をコメントアウトし、タイトルとサブタイトルを得ました。

更新されたコード

/* 
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 
} 
関連する問題