Search code examples
uiviewxamarinxamarin.iosstoryboardxamarin-studio

Custom UIView in Xamarin Storyboard


Does anyone know if we can design our custom UIViews in Xamarin's storyboards ? I would like to use autolayout and size classes for a custom View that I need to develop. I am not much comfortable with Xcode, having been so attached to Xamarin's IB. So I would prefer to design it in Xamarin storyboards than going for XIB files. I know we can prototype UITableViewCells in storyboards, but that is not what I want. I want a standalone custom UIView, with a code-behind class that I can re-use.


Solution

  • I have found out a way. But it is kind of a hack and will increase bundle size and thus a memory-inefficient way. First add a View Controller to the storyboard and give a class name to create a code behind, say "DummyViewController". Then drag a UIView to DummyViewController and in "properties" pane give "class" name as the name of the Custom View as shown in the image. Custom View's class name

    A code behind for this View will be created in project folder, MyCustomView inheriting from UIView. Now we can design the view from within XS storyboard with AutoLayout and Size Classes without a separate XIB file.

    I do not recommend this unless you really want it to be done this way. Hope Xamarin will come up with a solution to design Custom Views from within XS soon.