這裏有一個小問題..MKAnnotationView不顯示圖像
我已經做了一些代碼,應該改變得到的在圖形頁面放棄了銷的形象。 「taxi.png」的網址適用於圖片視圖,因此這不是當前的問題。
我也試過:
pinView?.image = UIImage(named: "taxi.png")
代碼:
if pinView == nil{
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView?.canShowCallout = true
var imageTaxi = UIImage(named: "taxi.png")!
imageTaxi = imageTaxi.withAlignmentRectInsets(UIEdgeInsetsMake(0, 0, imageTaxi.size.height/2, 0))
pinView?.image = imageTaxi
}
let button = UIButton(type: .detailDisclosure)
pinView?.rightCalloutAccessoryView = button
return pinView
是否有人看到這裏應該固定觀看的圖像?
編輯: 我現在有這個,我仍然有標準的紅色針尖..
let annotation = CustomPin()
annotation.coordinate = location
annotation.title = "Boek Taxi"
annotation.subtitle = ""
let image = UIImage(named: "taxi.png")
annotation.Image = image
self.mapView.addAnnotation(annotation)
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
if pinView == nil{
pinView = MKPinAnnotationView(annotation: CustomPin() as MKAnnotation, reuseIdentifier: reuseId)
pinView?.canShowCallout = true
} else {
pinView?.annotation = CustomPin() as MKAnnotation
}
let cpa = annotation as! CustomPin
pinView?.image = cpa.Image
let button = UIButton(type: .detailDisclosure)
pinView?.rightCalloutAccessoryView = button
return pinView
}
任何事情我已經漏掉了?
看一看這個[自定義圖釘圖像(http://stackoverflow.com/a/38159048/4080925) – MwcsMac
確認該代碼獲取調用所有(設置斷點和/或打印日誌語句)。也許代表沒有被指定,或者方法簽名是不正確的。如果不是這樣,他們請澄清一下:當你說有一個「問題」時,你究竟看到了什麼?紅色針?沒有?崩潰? – Rob