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

Creating a custom view


In this recipe, we will learn how to override the UIView class and/or classes that derive from it to create custom views.

Getting ready

So far, we have discussed many of the available views to create iOS apps. There will be many cases, however, we will need to implement our own custom views. In this recipe, we will see how to create a custom view and use it.

Note

Creating custom views is very useful when we want to capture touches or implement other custom behavior such as drawing.

Create a new iPhone Single View Application project in Xamarin Studio and name it CustomViewApp.

How to do it...

The following are the steps to complete this recipe:

  1. Add a new C# class file in the project and name it MyView.

  2. Implement it with the following code:

    using System;
    using MonoTouch.UIKit;
    using MonoTouch.Foundation;
    using System.Drawing;
    
    namespace CustomViewApp
    {
      [Register("MyView")]
      public class MyView : UIView
      {
    
        private UILabel labelStatus;
    
        public MyView (IntPtr handle...