Skip to content

Instantly share code, notes, and snippets.

@jacks205
Created April 5, 2015 01:35
Show Gist options
  • Save jacks205/0fe5613fbbbe6bd25675 to your computer and use it in GitHub Desktop.
Save jacks205/0fe5613fbbbe6bd25675 to your computer and use it in GitHub Desktop.
How to add a gradient layer to bezierpath swift
func fillTrafficIndicatorBase(ref : CGContextRef, rect : CGRect, cornerRadius : CGFloat, colorLight : CGColorRef, colorDark: CGColorRef, fillWidth : CGFloat){
CGContextSaveGState(ref)
let gradient : CGGradientRef = CGGradientCreateWithColors(Colors.genericRGBSpace(), [colorLight, colorDark], nil)
let path = UIBezierPath(roundedRect: rect, cornerRadius: cornerRadius)
path.fill()
path.addClip()
CGContextDrawLinearGradient(ref, gradient, CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)), CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)), 0)
CGContextRestoreGState(ref)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment