【发布时间】:2016-09-30 14:26:41
【问题描述】:
这是一个小问题..
我已经编写了一些代码来更改在 mapView 中放置的图钉的图像。 “taxi.png”的 url 适用于图像视图,所以这不是当前的问题。
我也试过了:
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
}
有什么我看过了吗?
【问题讨论】:
-
看看这个Custom pin image
-
确认此代码被调用(设置断点和/或打印日志语句)。可能未指定委托,或者方法签名不正确。如果不是这样,请他们澄清:当您说存在“问题”时,您到底看到了什么?红针?没有?崩溃?