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 text


In this recipe, we will learn how to draw styled text with an outline on a view.

Getting ready

Create a new Single View Application in Xamarin Studio and name it DrawTextApp. Add a custom view to the project, similar to the one we created in the previous recipe, and name it DrawingView.

How to do it...

Perform the following steps:

  1. Implement the following Draw method override in the DrawingView class:

    CGContext context = UIGraphics.GetCurrentContext();
    PointF location = new PointF(10f, 100f);
    UIFont font = UIFont.FromName("Verdana-Bold", 28f);
    NSString drawText = new NSString("This text is drawn!");
    context.SetTextDrawingMode(CGTextDrawingMode.Stroke);
    context.SetStrokeColorWithColor(UIColor.Black.CGColor);
    context.SetLineWidth(4f);
    drawText.DrawString(location, font);
    context.SetTextDrawingMode(CGTextDrawingMode.Fill);
    context.SetFillColorWithColor(UIColor.Yellow.CGColor);
    drawText.DrawString(location, font);
  2. In the ViewDidLoad method of the controller, initialize and display the DrawingView...