Anonymous White
Anonymous White

Reputation: 2159

What can we do so that users of our custom UIView can customize that UIView in XIB?

The biggest problem of custom UIView is that all we see is a white rectangle in XIB.

We can't customize some properties at all. For example, if our custom subView has a label, it's kind of nice to be able to set texts for that label straight in XIB.

enter image description here

Something like UIButton does.

Is this even doable?

Is XIB design merely as short cuts and that the real codes are in codes?

Upvotes: 3

Views: 1082

Answers (3)

AliSoftware
AliSoftware

Reputation: 32681

Unfortunately, there is no real way to add entries in the Interface Builder "Attributes Inspector" panel (the one on your capture) to allow your to customize values like you do for built-in Cocoa classes.


(well to be exact, some blogs explain some ways to convert old Xcode3 plugins — that were able to do that back in Xcode3 — to Xcode4 plugins, but this is not officially documented and quite complex to setup an needs a dedicated Xcode project just to create your custom view, declare its IB palette, write some associates code and embbed it in a xcode plugin…)


However, you still have one possibility, even if it is not very handy, to customize any property of any object in your XIB right in Interface Builder instead of doing it by code.

Simply go in the "Identity Inspector" (the tab before the Attributes Inspector, Cmd-Alt-3) and use the "User Defined Runtime Attributes" table to fill the name/keypath of the properties you want to change and indicate their value.

Customize value in IB from keyPath

In practice however, I have rarely seen it used in XIB files I work with, because it is not as nice as a dedicated "Attributes Inspector" palette, and you have to type the exact name of the property in the table so you can affect a value to it: there is no list of modifiable properties build for you with nice text fields and checkboxes in the panel to help you… but it still works like a charm!


Please feel free to send a request to Apple (using their feedback tools) to ask for this feature, as you are not the first one to hope this could be possible, and will not be the last to request it, so maybe hopefully Apple will receive enough requests and they will implement it…

Upvotes: 3

Tim Quinn
Tim Quinn

Reputation: 1

The storyboard/nib shows what the interface looks like before your code runs. If you want to see it in storyboard you have to build it in storyboard. If you have custom objects there is a basic object in storyboard to use as a placeholder, but it won't show content loaded in code.

Upvotes: 0

Ashbay
Ashbay

Reputation: 1661

Yes it's possible.

First, in your custom view add the following property (guessing you work with ARC feature) :

@property(nonatomic, strong) IBOutlet UILabel myLabel;

Now, in your xib, be sure the main view is the kind of your custom view. Add a label where you want in the view. Click on the custom view, and link the label to myLabel using the connection inspector.

Upvotes: 1

Related Questions