Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

A simple drawing app


In this recipe, we will use the techniques we learned to create a drawing app.

Getting ready

Create a new Single View Application in Xamarin Studio and name it FingerDrawingApp. Once again, we will need a custom view. Add a class deriving from UIView and name it CanvasView.

How to do it...

Perform the following steps:

  1. Implement the CanvasView class with the following code:

    public class CanvasView : UIView
    {
      public CanvasView (RectangleF frame) : base(frame)
      {
        this.drawPath = new CGPath();
      }
      private PointF touchLocation;
      private PointF previousTouchLocation;
      private CGPath drawPath;
      private bool fingerDraw;
      public override void TouchesBegan (NSSet touches, UIEvent evt)
      {
        base.TouchesBegan (touches, evt);
        UITouch touch = touches.AnyObject as UITouch;
        this.fingerDraw = true;
        this.touchLocation = touch.LocationInView(this);
        this.previousTouchLocation = touch.PreviousLocationInView(this);
        this.SetNeedsDisplay();
      }
      public override...