BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Building iOS/C# User Interfaces: Importing, Imperative, Drawing, or Drag and Drop

by Jonathan Allen on Jun 24, 2013 |

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.

Drag-and-Drop

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”.

Drawing

To augment your user interfaces you may consider looking at PaintCode. This is a vector drawing tool that exports Xamarin-compatible C# code instead of drawing primitives.

Imperative

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#.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT