指定图像注释,而不是针

问题描述:

嗨,伙计们我想要将我的注释上的图钉替换为自定义图像。指定图像注释,而不是针

我已经有我的image.cassette列表中的图像将显示1X 2X 3X等,但只要我尝试调用该图像我得到我的代码中的错误Xcode试图解决我的语法,但最终抛出它作为出错误

下面覆盖FUNC上市

我的代码

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然后将显示一个错误使用未解决的识别符“房子”

+0

什么错误说一个问题? – GeneCode

+0

使用未解析的标识符'House' – sabrefm1

夫特3引入图像字面的。只需写入“Imag”..并用Image Literal选项打开弹出窗口。像下面的图像:

enter image description here

通过选择“图片文字”选项,会弹出所有可用的资产图像,

要从电网使用

enter image description here

选择图像。

了解更多详情,see this

这段代码帮我固定我的问题

let pinImage = UIImage(named: "House.png") 
annotationView.image = pinImage 

,但我现在已经在我的地图不集中了