指定图像注释,而不是针
问题描述:
嗨,伙计们我想要将我的注释上的图钉替换为自定义图像。指定图像注释,而不是针
我已经有我的image.cassette列表中的图像将显示1X 2X 3X等,但只要我尝试调用该图像我得到我的代码中的错误Xcode
试图解决我的语法,但最终抛出它作为出错误
我的代码
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else {
return nil
}
let annotationIdentifier = "AnnotationIdentifier"
var annotationView: MKAnnotationView?
if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) {
annotationView = dequeuedAnnotationView
annotationView?.annotation = annotation
}
else {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
}
if let annotationView = annotationView {
annotationView.canShowCallout = true
annotationView.image = UIImage(named: "House")
}
return annotationView
}
现在Xcode
这里代码annotationView.image =的UIImage拿起一个错误(命名为:“豪斯医生”),其中要求它插 ”,”最终的结果是这样的
annotationView.image = UIImage(named: "#imageLiteral(resourceName: ",House,")")
Xcode
然后将显示一个错误使用未解决的识别符“房子”
答
夫特3引入图像字面的。只需写入“Imag”..并用Image Literal选项打开弹出窗口。像下面的图像:
通过选择“图片文字”选项,会弹出所有可用的资产图像,
要从电网使用选择图像。
了解更多详情,see this
答
这段代码帮我固定我的问题
let pinImage = UIImage(named: "House.png")
annotationView.image = pinImage
,但我现在已经在我的地图不集中了
什么错误说一个问题? – GeneCode
使用未解析的标识符'House' – sabrefm1