gabor.orosz
gabor.orosz

Reputation: 443

How to add a custom UIButton to Interface Builder Object Library?

Is that possible to add a subclassed UIButton to XCode 4.5 Interface Builder Object Library, but as Custom Object?

Here you can find the small sample project:
https://www.dropbox.com/s/ioucpb6jn6nr0hs/blabla1.zip

Upvotes: 5

Views: 2834

Answers (2)

Darren
Darren

Reputation: 10129

It isn't possible to add new objects to the Interface Builder Object Library, but you can drag a regular UIButton out, and change the Custom Class property to you custom class name in the 3rd tab of the Identity Inspector. You wont see any of your customizations in the xib file though.


I took a look at your sample code. In the BlaButtonVC.m you have the method

- (id)initWithFrame:(CGRect)frame

This doesn't get called when you're initing from the xib. You need to add the code in that method to

- (id)initWithCoder:(NSCoder*)coder

I tested it and it worked.

As an aside, I don't think BlaButtonVC is a good name, because it implies that your class is a view controller, when it is actually a view (unless VC stands for something else in your project).

Upvotes: 4

Max
Max

Reputation: 587

You used to able to do this in Xcode 3, but if I remember correctly it was a plugin thing (BWToolkit used to do it and was discontinued with Xcode 4). You can make a regular UIButton and change its class in the inspector window to the same effect though.

Upvotes: 1

Related Questions