Best approach to a complex custom UITextView

ElliotBlackburnElliotBlackburn USMember, University

I've got some fairly complex UITextView behaviour that I've added for a screen and now I'd like to re-use that in other areas. Generally there seem to be a two different approaches to creating this component; extending UIView and using code to create the component, creating a new iOS view xib along with a .cs (and optionally a designer.cs as well).

We're using xib's for all of our screen layouts with code for our custom interaction and behaviour so having an element that I can place in the xib rather than creating and positioning it with code would be great. However things get a bit more complex because of auto-layout, the custom component itself makes use constraints to change things like height and width which may start as a different value on different screens. For example on one screen we may wish to start this element at 10x10 and then have it change based on our behaviour rules to 50x50, on other screens we may want it to start at 20x45 etc. We're using auto-layout for all our xibs so we really need to change dimensions based on constraints rather than the frame/bounds.

I'm not really fussed about inheriting from UITextView or from UIView and using composition to wrap around a UITextView, both should work but I'm wondering which approach to take. Does a xib + code give any benefits and is it as easy to render in the XCode Interface Builder? Will it be simpler to build the whole thing through code? Does anyone have any Xamarin based examples as I've only found Objective-C ones so far, which is fine but not as easy to work from.


  • ElliotBlackburnElliotBlackburn USMember, University

    It's been a few days so I thought I'd bump this, really looking for a decent way to approach this. Any suggestions or ideas would be greatly appreciated!

Sign In or Register to comment.