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