-1
我試圖讓自定義引腳圖像顯示在我的mapView中,它呈現常規的紅色引腳而不是我的自定義圖像。我究竟做錯了什麼?不會顯示自定義引腳圖像
ViewFor譯註:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let reuseID = "pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseID) as? MKPinAnnotationView
if(pinView == nil) {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseID)
pinView!.canShowCallout = true
pinView!.animatesDrop = false
pinView?.image = UIImage(named: "CustomPinImage")
pinView!.rightCalloutAccessoryView = UIButton(type: UIButtonType.detailDisclosure) as UIButton
let smallSquare = CGSize(width: 40, height: 40)
let button = UIButton(frame: CGRect(origin: CGPoint.zero, size: smallSquare))
button.setBackgroundImage(UIImage(named: "Car2"), for: UIControlState())
pinView?.leftCalloutAccessoryView = button
}
else
{
pinView?.annotation = annotation
}
return pinView
}
如何我顯示引腳:
let LitzmanLocation = CLLocationCoordinate2DMake(32.100668,34.775192)
let Litzman = MKPointAnnotation()
Litzman.coordinate = LitzmanLocation
Litzman.title = "Litzman Bar"
Litzman.subtitle = "נמל תל אביב 18,תל אביב"
mapView.addAnnotation(Litzman)
這將是巨大的,如果有人可以幫助我整理了這一點!
謝謝:)
謝謝!有用 ! –