Skip to content

joaodragao/JLTGradientPathRenderer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

JLTGradientPathRenderer

Renders MKPolyline with a fancy multicoloured gradient fill similar to the Nike + Running App. A drop in replacement for MKPolylineRenderer, supports multiple colour stops and an optional border.

Installation

  1. Add JLTGradientPathRenderer.swift to your project
  2. Inside rendererForOverlay delegate method, use JLTGradientPathRenderer as you would an MKPolyLineRenderer
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
    if overlay is MKPolyline {
            /* define a list of colors you want in your gradient */
            let gradientColors = [UIColor.greenColor(), UIColor.blueColor(), UIColor.yellowColor(), UIColor.redColor()]
            /* Initialise a JLTGradientPathRenderer with the colors */
            let polylineRenderer = JLTGradientPathRenderer(polyline: overlay as! MKPolyline, colors: gradientColors)
        	/* set a linewidth */
            polylineRenderer.lineWidth = 7
            return polylineRenderer
    }
}
  1. Optionally include border and borderColor variables to render a border on the polyline
polylineRenderer.border = true
polylineRenderer.borderColor = UIColor.redColor() /* defaults to white if not specified*/

About

Renders MKPolyline with a fancy multicoloured gradient fill

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%