2016-11-30 57 views
1

嗨,夥計們我想要將我的註釋上的圖釘替換爲自定義圖像。指定圖像註釋,而不是針

我已經有我的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

回答

0

夫特3引入圖像字面的。只需寫入「Imag」..並用Image Literal選項打開彈出窗口。像下面的圖像:

enter image description here

通過選擇「圖片文字」選項,會彈出所有可用的資產圖像,

要從電網使用

enter image description here

選擇圖像。

瞭解更多詳情,see this

0

這段代碼幫我固定我的問題

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

,但我現在已經在我的地圖不集中了