Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drag custom view onto window in Interface Builder?

I'm coming from the world of C# and Winforms where I can build a custom UserControl and drag it onto a form as if it were a common control. Is there a way to do that in Xcode and Interface Builder?

I've only seen how to set the view at runtime but I'd like to see it on my window at design time. For example, I'd expect my custom view to be listed in the available controls.

Thanks!

Simon

like image 841
simon.d Avatar asked Aug 08 '12 19:08

simon.d


3 Answers

Interface Builder doesn't add (or allow the addition of, now that IB Plugins are derelict) Custom Objects to the Object Library. You can only drag in existing/preset objects, but you can have IB instantiate them as instances of a subclass as long as they are instantiated the same way.

E.g. Drag in a custom view and set the class to MyCustomViewClass, or drag in a scroll view and set the class to MyCustomScrollView, or drag in an object and set the class to CustomObject, et cetera.

And that is the preferred way of using custom controls in Interface Builder.

enter image description here

like image 78
Vervious Avatar answered Nov 12 '22 21:11

Vervious


Basically just ripping off rdelmar's comment... but I thought a picture would be helpfulenter image description here

Drag a normal view into IB, then select it and do this.

like image 38
Dustin Avatar answered Nov 12 '22 20:11

Dustin


Every Window you create in IB has a view on it as its first subcomponent. You dont need to create a separate custom view for it. If you really are subclassing it just change the class name in the inspector.

like image 32
deleted_user Avatar answered Nov 12 '22 21:11

deleted_user