Has anyone attempted to subclass MKOverlayPathView
in order to, essentially, recreate MKPolylineView
with more control of the path drawing? If so, would you be willing to share some example code?
I want to draw an MKPolyline
on a map view but MKPolylineView
does not offer enough flexibility in how the path is drawn. For instance I want to add a stroke and highlight on the line like the routes seen in the Maps app.
I came across this today when I was looking for a way to draw a border around an MKPolylineView
. After a bit of research and digging around, I created my own simple subclass of MKOverlayPathView
which works as a drop-in replacement of MKPolylineView
and adds support for drawing a border.
It ended up being very simple, you can take a look at the sample code on GitHub ASPolylineView or take a look at my brief blog post describing the main things that need to be done. It's a good building block to get started with more advanced custom drawing. For a more sophisticated subclass of MKOverlayPathView
, take a look at AIMapViewWrapper - especially the AIOverlayRouteView
class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With