Swift - Changing Annotation Image Not Working

天涯浪子 提交于 2019-12-05 19:31:03

The issue is that you're using MKPinAnnotationView. If you use MKAnnotationView, you will see your image.

In the past (e.g. iOS 8), setting the image of MKPinAnnotationView seemed to work fine, but in iOS 9 and later, it uses a pin, regardless (which is not entirely unreasonable behavior for a class called MKPinAnnotationView; lol).

Using MKAnnotationView avoids this problem.

Call that before return

if let annotationView = annotationView {
    // Configure your annotation view here
    annotationView.image = UIImage(named: "RaceCarMan2png.png")
}

return annotationView

and check with breakpoint if it is ok inside if

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