KMGradient
KMGradient
is a super-easy way to draw linear or radial gradients, be it in drawRect:
in a custom view or an image context.
Why?
Because creating and drawing a gradient with Core Graphics
functions is super-tedious.
Examples
NSArray *colors = @[[UIColor redColor], [UIColor yellowColor]];
NSArray *locations = @[@0.0, @1.0];
KMLinearGradient *gradient = [KMLinearGradient gradientWithColors:colors locations:locations];
CGPoint startPoint = CGPointMake(0.0, CGRectGetHeight(rect) / 2.0);
CGPoint endPoint = CGPointMake(CGRectGetWidth(rect), CGRectGetHeight(rect) / 2.0);
KMGradientDrawingOptions options = KMGradientDrawingOptionsDrawsAfterEndLocation | KMGradientDrawingOptionsDrawsBeforeStartLocation;
[gradient drawWithStartPoint:startPoint endPoint:endPoint options:options];
NSArray *colors = @[[UIColor redColor], [UIColor yellowColor]];
NSArray *locations = @[@0.0, @1.0];
KMRadialGradient *radialGradient = [KMRadialGradient gradientWithColors:colors locations:locations];
CGPoint startCenter = CGPointMake(CGRectGetWidth(rect) / 2.0, CGRectGetHeight(rect) / 2.0);
CGFloat startRadius = CGRectGetWidth(rect) / 2.0;
CGPoint endCenter = startCenter;
CGFloat endRadius = startRadius / 2.0;
KMGradientDrawingOptions options = KMGradientDrawingOptionsDrawsAfterEndLocation | KMGradientDrawingOptionsDrawsBeforeStartLocation;
[radialGradient drawWithStartCenter:startCenter startRadius:startRadius endCenter:endCenter endRadius:endRadius options:options];
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request