2017-01-16 7 views
0

私は何十もの注釈を持つ地図を持っています。アノテーションにはタイトルとサブタイトルが正しく表示されています。その右側にカスタムの[移動]ボタンを追加します。 [Go]ボタンをクリックすると、Apple Mapsが開き、地図上で見ていたアノテーションをユーザーに指示できます。map注釈は表示されませんrightCalloutAccessoryViewのカスタムUIButton

下記のコードをコピーしました。現在のフォームでは、ボタンは表示されません。

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 
    if !(annotation is MKUserLocation) { 
     let pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: String(annotation.hash)) 

     let rightButton = UIButton(type: .custom) 
     rightButton.setImage(UIImage(named: "Go"), for: .normal) 
     rightButton.tag = annotation.hash 

     pinView.canShowCallout = true 
     pinView.rightCalloutAccessoryView = rightButton 

     return pinView 
    } 
    else { 
     return nil 
    } 
} 

私は次の行削除する場合:

rightButton.setImage(UIImage(named: "Go"), for: .normal) 

をし、それを超えるものを変更します。それはとの問題だと私に語った、

let rightButton = UIButton(type: .detailDisclosure) 

は、ボタンが正しく表示されませんボタンのカスタムイメージを使用しようとしました。

何が欠けているのですか?

答えて

0

私は次のUIButtonの種類を変更することで、それを修正することができました:

let rightButton = UIButton(type: .infoLight) 

私のコードスニペットは、今ではなります

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 
    if !(annotation is MKUserLocation) { 
     let pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: String(annotation.hash)) 

     let rightButton = UIButton(type: .infoLight) 
     rightButton.setImage(UIImage(named: "Go"), for: .normal) 
     rightButton.tag = annotation.hash 

     pinView.canShowCallout = true 
     pinView.rightCalloutAccessoryView = rightButton 

     return pinView 
    } 
    else { 
     return nil 
    } 
} 
関連する問題