Tag Archives: iOS

Creating a custom native control using Xamarin.iOS

A lot of apps need more customized UI than what is available with the current set of controls. Today we’ll add a customized Check Box control since iOS does not have a Check Box. Some suggest that you use the Switch control as a replacement for the Check Box, but when developing custom apps and the client or boss want a check box, then I tend to implement a check box while others say it cannot be done. I’ll show the basics of creating a custom control for iOS of a check box.

Right click on your Xamarin iOS project and select Add Item.

Creating a Custom Native Control by Jeff Wyzard

In the Add New Item Window, Select “UIView” and give it a name for your custom control. After giving your control a name, click the Add button so Visual Studio add the file(s) to your project.

We need to modify the register attribute on the class to add DesignTimeVisible(true)

Creating a Custom Native Control by Jeff Wyzard

Now we will add any properties that we’ll need for customizing our new control and we’ll use the Visual Studio code snippet “propfull”. In the class, type propfull and hit the tab key twice.

Creating a Custom Native Control by Jeff Wyzard

Visual Studio will add some code to your class with default type of int and named “MyProperty” with the property type, name, name of the class and default value highlighted

Creating a Custom Native Control by Jeff Wyzard

You can change the different highlighted options and press the tab key to go from one highlighted option to another. In my case, I wanted a Boolean property named “IsChecked” with a default false as the default value.

Creating a Custom Native Control by Jeff Wyzard

We need to add an attribute Export with the property name and the property will be browsable.

Creating a Custom Native Control by Jeff Wyzard

Now we can start drawing portion of the custom control. Type override and select the Draw method with the CGRect argument since we’ll need to override the Draw method for the drawing.

Creating a Custom Native Control by Jeff Wyzard

Next in the Draw, we can draw the box for our check box control.

Creating a Custom Native Control by Jeff Wyzard

You can do whatever you need to do in the Draw method to create your custom control.

Have fun!

Follow me online to learn about creating Xamarin Forms custom view that uses these custom native controls.
My Blog: www.wyzard.us
LinkedIn: https://www.linkedin.com/in/jeff-wyzard-b89a7011


Getting the Xamarin Certified Mobile Developers Badge

In December of 2016, I decided that I wanted the Xamarin certification since more of my development projects were on iOS, Android and UWP mobile devices. I am now a Xamarin Certified Mobile Developer as of January 1, 2017.

I wanted to share my experience with Xamarin University and certification testing. I am also Microsoft C# Certified Professional, so that saved time in learning portions of C# that some coming from web technologies would need to learn. Since I’ve been developing with WPF when it was an add-on to Visual Studio 2005, working with XAML, XAML styles, triggers, templates, etc. made the move to Xamarin Forms easier.

If you are a developer who has been wondering about the Xamarin University classes and if they are worth it, the answer is emphatically, YES! Xamarin development tools have never been documented very well, in my opinion (I hear the same comment from other developers), so finding out how to do different routines was a matter of finding the right blog or forum.

Xamarin University has classes on more than the Xamarin tools, which is great. Some of the classes cover using 3rd party tools with Xamarin like SQLite, Azure, C# and classes are mostly 2 to 3 hours each. There are different instructors offering most of the classes at different times of the day/month so a class at one time is bad for you, they probably offer it again at a different time, so no matter where you live or your work schedule, a class should be available. The classes were structured very well with slides, exercises and the instructors, at times, even had flash quiz or two. Most all the instructors were nice, tried to involve the students and were great about answering questions plus at the end of the classes, they would hang around to make sure they answered any questions about the class. If you had questions related to the topic that they could not answer about the class, they followed up very quickly.

The certification exam is much better coverage of the programming matter than other exams that I have taken over the years. Other exams tend to focus on new features or items that the company believes are import even if you do not use those features in your career. I do think the Xamarin certification exam could be improved by removing the opinion based questions where there are multiple methods to accomplish the same goal instead of asking which is better based on one person’s opinion. In the real world, “which is better” will depend on other factors which the test is not able to take into consideration. The Xamarin Certification Exam Study Guide is extremely helpful.  Be sure to review it since some material covered on the exam is not covered very well in the certification classes.

Overall the classes and exam were a great and fun experience, highly recommended and  I give it two thumbs up!