如何在故事板中添加自定义UIControl类?

时间:2014-09-05 23:23:46

标签: ios objective-c swift storyboard uicontrol

我有一个我想在故事板中使用的自定义UIControl类。我遇到问题,因为Storyboard控制台中的对象库中没有UIControl。

我尝试添加一个UIView并为其分配我的自定义UIControl类,但它似乎没有注册我需要控件使用的事件(Value Changed,Touch Drag Inside,Touch Up Inside)。

调试时,我打破了与事件相关的动作,看起来甚至没有被调用。

如何在故事板中正确使用我的自定义UIControl类?

2 个答案:

答案 0 :(得分:30)

您正确地执行此操作 - 将UIView放到故事板上并在Identity Inspector中分配该类。不要忘记在自定义类中覆盖initWithCoder:aDecoder

答案 1 :(得分:0)

好吧, 因此,正如我最近弄清楚的,每当我们需要通过某个第三方库使用自定义控件时, 我们必须做:    以需要通过Interface Builder添加到项目中的TwicketSegmentedControl UIControl类为例,然后:-

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.

就是这样。完成。

现在使用文件中的IBOulet访问它。

对于其他任何问题,如果需要调试代码,请检查是否在库文件中调用了-initWithCoder。