Gradient along MKPolyLineView ( MKPolylineRenderer )
I’d like to apply a gradient on a polyline view depending on some conditions like speed.
I was able to subclass
MKPolyLineRenderer to draw with custom stroke and fill, but only with the same color along the path.
I saw other similar questions like : Draw segments from a circle or donut or On OSX, how do I gradient fill a path stroke? , but it is not exactly what I’d want.
If I understand correctly, a path like below couldn’t be filled with these methods. At least not treated as a whole.
A very similar question is Gradient Polyline with MapKit ios. But it adds an overlay for each segment between the points, which I think isn’t too efficient.
Is this the only possible way ? ( I’d need to draw hundreds or maybe thousands of these segments … ) How can this be achieved easily ?
- Draw polyline in mapview iOS 6
- MKPolyline / MKPolylineRenderer changing color without remove it
- Creating an MKMapSnapshotter with an MKPolylineRenderer
- UnsafeMutablePointer in swift as replacement for properly sized C Array in Obj-C
- iOS 8 SDK, Swift, MapKit Drawing a Route
- Polyline not drawing from user location (blue dot)
Solutions Collect From Internet About “Gradient along MKPolyLineView ( MKPolylineRenderer )”
So the original answer is here https://stackoverflow.com/a/20159374/2606068
you can find the demo here https://github.com/wdanxna/GradientPolyline
and some improvement tips provided by @Templar is:
- prepare the path directly in the init.
- check also for CGRectContains, not only for intersection.
thanks man! :p
- UITextView Auto Height
- RTSP/RTMP Video Streaming Client iOS
- Will changing the product name cause problem?
- clang-format style options for enums
- AWS MobileHub iOS SDK – AWSSignInProvider – No documentation for class
- HTML character decoding in Objective-C / Cocoa Touch
- How to check if an variable of any type is an array
- Difference between self.var and simply var
- In a UICollectionView how can I preload data outside of the cellForItemAtIndexPath to use within it?
- Decode Base-64 encoded PNG in an NSString
- How to fit a certain bounds consisting of NE and SW coordinates into the visible map view?
- will the retained/strong class member variables got automatically clean'd up on unloading a view controller?
- Is it possible to reset the privacy settings in iOS?
- cloudkit: how to access main user's attributes?
- How to target 4.2 version with XCode 4