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 ?
- rotate image using CGContextDrawImage
- How to Convert UIView to PDF within iOS?
- Add subview with UIAlertVIew like animation,with a bouncing effect
- Decode images in background thread?
- Get Slightly Lighter and Darker Color from UIColor
- Better quality image from UIGraphicsGetImageFromCurrentImageContext()
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
- real time plotting on iPhone using core plot?
- Unable to add margin/padding to text in UILabel – iOS Swift
- Post image and text from iPhone to asp.net
- Scheme Script vs. Build Phase Script
- Unwanted Tablecells showing
- iOS 8 Swift Read Plist
- Get outlet size within awakeFromNib
- How to record sound produced by mixer unit output (iOS Core Audio & Audio Graph)
- Autoscrolling infinite effect in .linear type of iCarousel in swift
- Create and import swift framework
- NSURLSession background download – resume over network failure
- Detect Change in UILabel Text
- Siesta iOS GET request with url parameters
- Type Alias Declaration with templates in Swift
- Parse Framework with Swift