Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I create a reusable UIView that I can drag and drop in IB?
    text
    copied!<p>I'm working with XCode 4.5. For my current project, I need to build an UI element similar to a textfield. Because I will have to reuse this custom element in a whole bunch of ViewControllers, I'm looking for a way to build this custom textfield in such a way that I can use it for drag &amp; drop in the XCode interface builder, instead of adding it only programmatically (that's what I found so far).</p> <p>How can I achieve this? <em>I'm looking for a tutorial that explains the whole process in a simple example project.</em></p> <p><strong>Specification:</strong></p> <p>The result I'm going for is having a custom UIView that I can use just like every other predefined UI element (such as a textfield). That means I want to be able to drag &amp; drop it from the object library into some controller in my storyboard, edit its attributes, especially the custom ones, with the attributes inspector and get visual feedback about that changes in IB. I don't want to subclass predefined UIViews over and over again, for two reasons:</p> <ol> <li>First, adding custom a subclass to predefined UI elements means more work, since I need to repeat that over and over again for every single element I need to customize. More or less the whole visual part of my app will be build of custom UI elements to match a certain design I have to implement for my client.</li> <li>Second and more important, I literally don't get the picture how my UI will finally appear if I build the biggest part of it programmatically by customizing its appearance in subclasses that should hold custom functionality.</li> <li>Finally, I consider it a bad coding practice to break the beautiful MVC separation the iOS SDK provides by generating static UI parts of my program that will never change at runtime programmatically in the controller part.</li> </ol> <p>This is why I need to design a custom UI element (let's call its corresponding class UITextFieldCustom) that I can use in the process of designing the UI like any other premade library object such as a textfield. Is that possible?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload