One of the unfortunate realities in iOS development is that Apple doesn't provide you with a CheckBox control. Though this control is common to other platforms, Apple has directed users to either use a UISwitch or modify a UIButton to get similar behavior. Since there isn't an out-of-the-box solution for iOS, we've included a new Xuni CheckBox control with the 2016v1 release. checkbox_iphone_600

XuniCheckBox

A CheckBox is an uncomplicated control: it's a simple mechanism for displaying and collecting boolean data. The are only two states for the control, and the number of properties is minimal. Our solution, the XuniCheckBox control, is part of the XuniCore framework. The XuniCheckBox is small enough that I'll provide it here:


#import <UIKit/UIKit.h>  

/**  
 *  The XuniCheckBox control provides standard check box functionality for iOS  
 */  
@interface XuniCheckBox : UIButton <UIGestureRecognizerDelegate>  

/**  
 *  Gets or sets the state of the checkbox  
 */  
@property (nonatomic) BOOL isChecked;  

/**  
 *  Enables or disables user interaction  
 */  
@property BOOL isReadOnly;  


@end  

There are only a couple of properties that are unique to the control, though there are others inherited from UIButton. Usage of the control is straightforward, and you can configure the appearance (details like size and color) in a manner similar to a UIButton (by setting the frame and tintColor per this example).

Visual UISwitch/XuniCheckBox comparison

Compared to a UISwitch, the CheckBox allows you to represent boolean data with different styling. There are two different visual states for each control: Off / UncheckedOff / Unchecked On / CheckedOn / Checked A highlight of the new control is the built-in animation for checking or unchecking the CheckBox: CheckBox

Using the CheckBox in apps

The XuniCheckBox is an independent control, and it can be used where ever you think it could improve your app. One nice use case is checking off a list of reminders: Reminder Or the control can be used to represent boolean values in a FlexGrid: FGwithCB Though the control is new to the iOS platform, the XuniCheckBox is also available in Xamarin.iOS and Xamarin.Forms. Creating XuniCheckBox control fills in a specific gap between the different native platforms, and has a cascading effect on what Xuni provides in Xamarin.iOS and Xamarin.Forms (check out this blog for more information). In fact, we've updated the Xamarin.Forms version of FlexGrid to automatically use the CheckBox control to represent boolean values.

Conclusion

The new CheckBox is a small quality of life enhancement for iOS developers. The control bring more parity between platforms too, which will also help out Xamarin.Forms developers. There are a number of other Xuni controls out there too, and the Xuni platform page has a nice summary of what's available. We'll continue to examine what new features we can add to Xuni to bring parity between platforms and improve your apps.