Can any help me with making custom MKPolyline
with additional argument Color?
CustomPolyline.swift
import Foundation
im
As user3470987 pointed out, there might be an issue in modifying the default 'rendererForOverlay' delegate function. It could also prove difficult if you'd like to add overlays of other types than MKPolyline.
Class
import Foundation
import MapKit
class Polyline: MKPolyline {
var color: UIColor?
}
Render function
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if let polyline = overlay as? Polyline {
let polylineRenderer = MKPolylineRenderer(overlay: polyline)
polylineRenderer.strokeColor = polyline.color
polylineRenderer.lineWidth = 3
return polylineRenderer
}
return MKOverlayRenderer(overlay: overlay)
}