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

Drawing shapes


Following the example from the previous recipe, we will draw a circle and square on the screen.

Getting ready

Create a new Single View Application in Xamarin Studio and name it DrawShapeApp. Add a custom view to the project, like we did in the previous task, and name it DrawingView.

How to do it...

Perform the following steps:

  1. Override the Draw method of the DrawingView class and implement it with the following code:

    CGContext context = UIGraphics.GetCurrentContext();
    context.SetFillColorWithColor(UIColor.Blue.CGColor);
    context.SetShadow(new SizeF(10f, 10f), 5f);
    context.AddEllipseInRect(new RectangleF(100f, 100f, 100f, 100f));
    context.FillPath();
    context.SetFillColorWithColor(UIColor.Red.CGColor);
    context.AddRect(new RectangleF(150f, 150f, 100f, 100f));
    context.FillPath();
  2. In the ViewDidLoad method of the DrawShapeAppViewController class, initialize and display the view with the following code:

    DrawingView drawView = new DrawingView(new RectangleF(0f, 20f, this.View.Bounds.Width...