How to change MKMapView's user-location blue dot to an image of choice?

后端 未结 5 1529
盖世英雄少女心
盖世英雄少女心 2020-12-02 09:27

Is it possible to change the blue dot which indicates the user\'s location in MKMapView to an image? For example a little car or any .png image?

5条回答
  •  鱼传尺愫
    2020-12-02 10:06

    Ok, here is the Swift version:

    func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
    
        let identifier = "User"
    
            var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
    
            if annotationView == nil{
                annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
                annotationView.canShowCallout = true
    
            } else {
                annotationView.annotation = annotation
            }
    
        annotationView.image = UIImage(named: "image")
    
        return annotationView
    
    }
    

提交回复
热议问题