Building iOS/C# User Interfaces: Importing, Imperative, Drawing, or Drag and Drop
In the past the way iOS user interfaces were created in C# the same way they were created in Objective-C; developers would fire up XCode and use the drag-and-drop interface to layout the screen, then save the results in a massive xml file known as a Xib. But that’s not all, then the developer has to manually create outlets and actions for the rest of the application to hook into.
For C# developers yet another step is required. The result of all that has to be moved from XCode into MonoDevelop. At least that was the case until Xamarin Studio was released with an integrated iOS designer.
In his introduction to Xamarin’s iOS designer, Ryan Paul discusses the time saving features of the product,
Unlike Xcode, the new iOS designer in Xamarin Studio does all of that work behind the scenes. To expose an iOS control to source code in Xamarin Studio, the user simply has to click the control in the storyboard and type a value into the Name field in the properties panel. When a control is given a name, Xamarin Studio will automatically generate an outlet for it in the code-behind.
Xamarin Studio also makes it very easy to add event handlers. When the user double-clicks a button on the design surface, Xamarin Studio will automatically add a new method bound to the button’s TouchUpInside event to the class associated with the button’s parent view controller. The user can also create a handler for a specific event by using the events tab of the properties panel.
Custom controls can be registered in the designer simply by added the “Register” attribute to the control’s class definition. Unlike XCode, these custom controls even support live rendering of controls “that are painted with custom drawing code”.
Michael James argues going the other route. Instead of using increasing sophisticated tooling, he suggests that you instead consider creating your user interfaces imperatively. In the image below you can see the massive amount of XML needed for a simple screen and the handful of lines required to do the same thing in C#.
Stuart Williams Aug 02, 2015
David Beyer, Olaf Carlson-Wee, Richard Minerich Aug 02, 2015