In this recipe, we will implement custom drawing to draw two lines on a UIView
class.
Perform the following steps:
Add a new class to the project and name it
DrawingView
. Derive it fromUIView
as follows:public class DrawingView : UIView
Add the following
using
directives in theDrawingView.cs
file:using MonoTouch.CoreGraphics; using MonoTouch.UIKit; using System.Drawing;
Add the following constructor to the class:
public DrawingView(RectangleF frame) : base(frame) {}
Override the
Draw
method ofUIView
and implement it with the following code:public override void Draw (RectangleF rect) { base.Draw (rect); Console.WriteLine("DrawingView draw!"); CGContext context = UIGraphics.GetCurrentContext(); context.SetLineWidth(5f); context.SetStrokeColorWithColor(UIColor.Green.CGColor); context.AddLines(new PointF[] { new PointF(0f, this.Bounds.Height), ...