UIImage Cropping Library for Xamarin iOS

We just released a binding project for Tim Oliver’s TOCropViewController library on our public GitHub repository . This iOS binding project provides a view controller allowing users to crop UIImage objects.

In one of our Xamarin iOS projects, we needed a way to crop images. We looked for existing libraries and could not find a Xamarin iOS one that satisfied our needs.

One library drew our attention though: TOCropViewController, a UIIMage cropping project made by Tim Oliver, allowing users to crop and rotate UIImage with an iOS look and feel.

The only problem being: it is an Objective-C library. We decided to create a binding project, using Objective Sharpie.

The process to create a binding library project and exposing APIs similar to .NET is already described here and here. This project has something new to the process that neither of our previous blog posts talked about: How to support the iOS simulators.

Simulator support for iOS Bindings

To support the iOS simulator, you need to compile the Objective-C code with the i386 architecture as well. However iPhone devices don’t support it so we need to modify the build configuration in the Xcode project. First we need to modify the valid architecture of the project’s target (here TOCropViewController) to have both Any iOS SDK and Any iOS Simulator SDK. The iOS SDK should have arm64, armv7 and armv7s while the iOS Simulator SDK should have i386. A similar modification should be done to Architecture. We need to add both iOS Simulator SDK and iOS SDK with the correct supported architectures (the simulator having i386 and iOS having at least armv7 and arm64).


Then we need to build the archive of both the simulator and the iOS SDK by using the Archive option under the Product menu. Finally we needed to get the 2 resultant .a files and merge them using lipo.

After we run the archive tool, we just have to drop the final fat .a in our binding project as well as the ApiDefinition.cs and StructsAndEnums.cs files produced by ObjectiveSharpie as described here. Finally, we just have to add the ShowCropViewAsync function to expose the .NET like call (hiding the need to use the delegates inside the binding library and therefore having to do less boilerplate code on the app side).

How to use this binding project

  • Add the project to your Xamarin solution

  • Add a reference to this project to your iOS project

Code sample

A class to encapsulate the cropping service

Usage in a ViewModel


Simulator Screen Shot May 26, 2016, 11.49.34 AM Simulator Screen Shot May 26, 2016, 11.49.59 AM Simulator Screen Shot May 26, 2016, 11.50.01 AM

Recent Posts

Leave a Comment