In this recipe, we will learn how to override the UIView
class and/or classes that derive from it to create custom views.
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
.
The following are the steps to complete this recipe:
Add a new C# class file in the project and name it
MyView
.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...