Custom annotation showing same image for all different types of POI's

久未见 提交于 2019-12-04 20:45:26

can you try to change:

}else if  {

into:

else if(state == "Jachthavens")

update:

check subtitle instead of state:

if annotationView == nil {

    annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "pin")
    annotationView!.canShowCallout = true

    if(annotationView.subtitle == "track") {
        annotationView!.image = UIImage(named: "startpin")
    } else if(annotationView.subtitle == "pause") {
        annotationView!.image = UIImage(named: "pausepin")
    } else if(annotationView.subtitle == "stop") {
        annotationView!.image = UIImage(named: "endpin")
    } else if (annotationView.subtitle == "Jachthavens") {
        annotationView!.image = UIImage(named: "jachthavenpin")
        let deleteButton = UIButton(type: UIButtonType.Custom) as UIButton
        deleteButton.frame.size.width = 35
        deleteButton.frame.size.height = 35
        deleteButton.backgroundColor = UIColor.whiteColor()
        deleteButton.setImage(UIImage(named: "jachthaven"), forState: .Normal)
        deleteButton.addTarget(self, action: #selector(ViewController.infoClicked(_:)), forControlEvents: .TouchUpInside)
        annotationView!.leftCalloutAccessoryView = deleteButton
        annotationView?.annotation = annotation
    } else if (annotationView.subtitle == "Watersportwinkels") {
        annotationView!.image = UIImage(named: "watersportwinkelspin")
        let deleteButton = UIButton(type: UIButtonType.Custom) as UIButton
        deleteButton.frame.size.width = 35
        deleteButton.frame.size.height = 35
        deleteButton.backgroundColor = UIColor.whiteColor()
        deleteButton.setImage(UIImage(named: "watersportwinkels"), forState: .Normal)
        deleteButton.addTarget(self, action: #selector(ViewController.infoClicked(_:)), forControlEvents: .TouchUpInside)
        annotationView!.leftCalloutAccessoryView = deleteButton
        annotationView?.annotation = annotation
    }

} else {
    annotationView!.annotation = annotation
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!