Skip to content

Instantly share code, notes, and snippets.

@joewest
Last active December 25, 2015 15:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joewest/6997432 to your computer and use it in GitHub Desktop.
Save joewest/6997432 to your computer and use it in GitHub Desktop.
Drawing a CGGradient in Monotouch
var bounds = Bounds;
var context = UIGraphics.GetCurrentContext ();
// Gradient using CGGradient
PointF start = new PointF (0.0f, 0.0f);
PointF end = new PointF (0.0f, bounds.Height-(bounds.Height*0.20f));
CGGradient gradient;
using (var rgb = CGColorSpace.CreateDeviceRGB ()) {
float[] color1 = new float[] { 0.0f, 0.0f, 0.0f, 0.0f }; // Black Clear
float[] color2 = new float[] { 0.0f, 0.0f, 0.0f, 1.0f }; // Black
float[] colors = new float[color1.Length + color2.Length];
Array.Copy (color1, colors, color1.Length);
Array.Copy (color2, 0, colors, color1.Length, color2.Length);
gradient = new CGGradient (rgb, colors, null);
}
context.DrawLinearGradient (gradient, start, end, CGGradientDrawingOptions.DrawsAfterEndLocation);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment