Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add custom UIControl subclasses graphically in IB in Xcode 4?

Tags:

xcode

ios

I want to use Matthijs Hollemans' MHRotaryKnob control in my iOS 5 app. I am using a storyboard in Xcode 4.2. MHRotaryKnob is implemented as a subclass of UIControl.

I'm unable to replicate the example he provides and thus unable to add the control to my app's view. In the example, his XIB contains a view with an instance of MHRotaryKnob added to it as a custom control. It loads and runs fine but I can see no way in Xcode to do this for myself. I've tried adding every kind of UIControl subclass and changing their class in the Identity Inspector, but Xcode keeps changing them right back.

Any ideas?

Thanks

like image 827
Tim Avatar asked Nov 22 '11 02:11

Tim


2 Answers

The answer is to add a UIView to the view and change its class in the Identity Inspector, rather than trying to do that with buttons or other UIControls.

like image 81
Tim Avatar answered Oct 31 '22 09:10

Tim


When you changed the class of the UIView from the Identity Inspector, don't forget to add initWithCoder:aDecoder to your code, in the custom class.

like image 35
user2411400 Avatar answered Oct 31 '22 08:10

user2411400