Last active
December 25, 2015 15:19
-
-
Save joewest/6997432 to your computer and use it in GitHub Desktop.
Drawing a CGGradient in Monotouch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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