Xamarin on iOS – Mono Touch

The project that we created in the previous section used the Xamarin.Forms UI rendering. While this can be the most efficient way to implement a cross-platform application, in some cases, you might need to implement a very platform-specific application (this includes many platform APIs and specialized UI components). In these type of situations, you can resort to creating a classic Xamarin.iOS and/or Xamarin.Android application.

In a classic Xamarin application, views are created using native SDK components and toolsets. In the case of Xamarin.iOS, developers can create the application views either using an iOS namespace and UI elements using code or using XIBs or storyboards with backing controllers.

In order to recreate the implementation that was done on Xamarin.Forms for Xamarin.iOS, you can use the iOS application template listed under the iOS section.

This template will create a simple Xamarin.iOS application with a single view, an associated storyboard, and a controller for the main view that was created.

With either Visual Studio on Windows or macOS, you can make use of the designer, create the label control, and align it to be centered both horizontally and vertically with constraints referring to the containing view. In order to add the label, you can drag and drop the label control from the toolbox. Once the toolbox is added, constraints can be added using the designer. The iOS designer has two available modes, one of which is the constraint mode. In this mode, you can hold the center pin and drag it to the superview vertical center. You can repeat this process for the horizontal center:

Now, if we compile and run the application, you will get the same view that was rendered by Xamarin.Forms in the previous section:

During the compilation process, the project that we created with C# and .NET (standard) modules is first compiled into a Microsoft Intermediate Language (MSIL), just like any other .NET Core project, and is then compiled into native code with AOT compilation. At this point, one of the most crucial components is the monotouch runtime, which acts as the adaption layer that sits on top of the iOS kernel, allowing the .NET Standard libraries access to the system-level functions. During compilation, just like the application code, the monotouch runtime libraries, together with the .NET Standard packages, are linked and trans(com)piled into native code.

The AOT compilation is only a requirement when the compiled package is being deployed to a real device because of the code generation restrictions on iOS. For other platforms or when running the application on an iOS simulator, a JIT compiler is used to compile MSIL into native code  not at compile-time, but at runtime.

The following screenshot outlines the transcompilation process of APT and LLVM for Xamarin.iOS applications: