You need to implement the MKMAPViewDelegate and override this method below :
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
inside this method just implement something like this :
Avoid user location pin
if (annotation is MKUserLocation) {
return nil
} else {
// HERE YOU CONFIGURE YOUR CUSTOM MKPinAnnotationView by also leveraging dequeue for performance
let annotationIdentifier = "AnnotationIdentifier"
// YOUR CUSTOM VIEW you want to add instead of the default one
let nibName = "MarkerView"
let viewFromNib = Bundle.main.loadNibNamed(nibName, owner: self, options: nil)?.first as! MarkerView
var annotationView: MarkerView?
// if there is a view to be dequeued, use it for the annotation
if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) as? MarkerView {
if dequeuedAnnotationView.subviews.isEmpty {
// HERE YOU ADD IT AS A SUBVIEW
dequeuedAnnotationView.addSubview(viewFromNib)
}
annotationView = dequeuedAnnotationView
annotationView?.annotation = annotation
} else {
let av = MarkerView(annotation: annotation as? CustomPointAnnotation, reuseIdentifier: annotationIdentifier)
av.addSubview(viewFromNib)
annotationView = av
}
...
...
////// ETC ETC of the configuration after regarding your annotation view
This should answer your issue.