Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a custom UIControl class in storyboard?

I have a custom UIControl class that I want to use in my storyboard. I am having problems since there isn't a UIControl in the object library in the Storyboard console.

I tried adding a UIView and assigning my custom UIControl class to it, but it seems to not register the events that I need for the control to use(Value Changed, Touch Drag Inside, Touch Up Inside).

When debugging, I breakpointed the actions related to the events and it looks like they are not even called.

How can I use my custom UIControl class correctly in my storyboard?

like image 377
3254523 Avatar asked Sep 05 '14 23:09

3254523


People also ask

How do you add a Uicontrol to a storyboard?

1. Drag UIView to your Design file 2. Replace default 'class name' in Identity Inspector of this Control from UIView to TwicketSegmentedControl 3. (Important step) Also Assign 'Module Name' below 'class name' in Identity Inspector to TwicketSegmentedControl.

How do I create a custom control in Swift?

In the storyboard, open the Assistant editor; it should display ViewController. swift. To create the outlet, click the Knob and control-drag it right underneath the animateSwitch IBOutlet . Release the drag and, in the pop-up window, name the outlet knob then click Connect.


1 Answers

You are doing it correctly -- drop a UIView onto your storyboard and assign the class in the Identity Inspector. Don't forget to override initWithCoder:aDecoder in the custom class.

like image 86
memmons Avatar answered Sep 20 '22 02:09

memmons