public static void FillRect(CGContext context, RectangleF rect, CGColor color) { context.SaveState(); context.AddRect(rect); context.Clip(); context.SetFillColor(color); context.FillRect(rect); context.RestoreState(); }
public static void DrawRect(CGContext context, RectangleF rect, CGColor color, float lineWidth) { context.SaveState(); context.AddRect(rect); context.Clip(); context.SetLineWidth(lineWidth); context.SetStrokeColor(color); context.StrokeRect(rect); context.RestoreState(); }
public static void FillGradient(CGContext context, RectangleF rect, CGColor color1, CGColor color2, bool isHorizontal) { CGGradient gradientBackground; CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB(); float[] locationListBackground = new float[] { 1.0f, 0.0f }; List<float> colorListBackground = new List<float>(); colorListBackground.AddRange(color1.Components); colorListBackground.AddRange(color2.Components); gradientBackground = new CGGradient(colorSpace, colorListBackground.ToArray(), locationListBackground); context.SaveState(); context.AddRect(rect); context.Clip(); //context.ScaleCTM(1, -1); if(isHorizontal) context.DrawLinearGradient(gradientBackground, new PointF(rect.X, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation); else context.DrawLinearGradient(gradientBackground, new PointF(0, 0), new PointF(0, rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation); context.RestoreState(); }