简体   繁体   English

如何将自定义类添加到情节提要?

[英]How do I add a custom class to a storyboard?

I am currently trying to implement a custom radio button class that I have been messing with (located at https://github.com/t4ku/RadioButtonWithUIKit ). 我目前正在尝试实现一个自定义的单选按钮类(位于https://github.com/t4ku/RadioButtonWithUIKit )。 This radio button solution draws everything programmatically. 此单选按钮解决方案以编程方式绘制所有内容。

I was wondering if there is a similar solution using buttons that were added via Storyboard. 我想知道是否存在使用通过Storyboard添加的按钮的类似解决方案。 I already have my design exactly how I want it through Storyboard and would much rather somehow "link" the buttons with my radio button class. 我已经通过Storyboard完全实现了我的设计,宁愿以某种方式将按钮“链接”到单选按钮类。

Any newer ideas or suggestions would be greatly appreciated. 任何新的想法或建议,将不胜感激。

You can change the class of an object on Storyboard in the identity inspector (you can manually enter the class instead of relying on the drop down menu). 您可以在身份检查器中的情节提要上更改对象的类(可以手动输入类,而不必依靠下拉菜单)。 You can then link the object however you like. 然后,您可以根据需要链接对象。

If Storyboard doesnt accept the RadioButton class for some reason you could also create a custom class of UIButton that would inherit from the RadioButton class and then use that in the same way. 如果Storyboard由于某种原因不接受RadioButton类,则还可以创建一个UIButton的自定义类,该类将从RadioButton类继承,然后以相同的方式使用它。

That control is based on UIView , so in your storyboard just add a new View object, select it, and then set the class (at the top of the image) to RadioButton : 该控件基于UIView ,因此在情节提要中只需添加一个新的View对象,选择它,然后将class (在图像顶部)设置为RadioButton

在此处输入图片说明

You won't be able to see anything but a blank view where you place it, but it will work properly when you launch the application. 除了空白视图,您将看不到其他任何东西,但是在启动应用程序时它将正常工作。 This will at least make it easier to resize, position, etc. 这至少将使其更容易调整大小,位置等。

If I understand your question right, to refer to a button added to a storyboard programmatically, you have to link the variable name in your .h file to the actual button in your .xib file. 如果我理解正确的问题,要以编程方式引用添加到情节提要中的按钮,则必须将.h文件中的变量名称链接到.xib文件中的实际按钮。 If you add the following line to your .h file 如果将以下行添加到.h文件中

@property (nonatomic) IBOutlet UIButton *theButton;

Then when you return to the .xib, there should a yellow cube (file's owner) to the left of the storyboard panel. 然后,当您返回.xib时,情节提要面板左侧应该有一个黄色的多维数据集(文件的所有者)。 If you right click on that cube, you should get a list of outlets. 如果在该多维数据集上单击鼠标右键,则应获得网点列表。 At the end of the line that has your button's name, there should a circle. 在具有按钮名称的行的末尾,应该有一个圆圈。 If you Ctrl+Click and Hold and drag it to the button in the storyboard, it should like the variable in the .h file to the button in the storyboard. 如果按住Ctrl键并单击并按住,然后将其拖动到情节提要中的按钮,则它将.h文件中的变量与情节提要中的按钮一样。

So now when you refer to the variable name you created, you will be referring to the button in the storyboard. 因此,现在当您引用创建的变量名称时,将引用情节提要中的按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Storyboard UIViewController与我的自定义UIViewController类相关联? - How do I associate a Storyboard UIViewController with my custom UIViewController class? 如何在故事板中添加自定义UIControl类? - How to add a custom UIControl class in storyboard? 如何在Xamarin.ios本机应用程序的自定义控制器类中打开新的故事板? - How do I open a new storyboard from custom controller class in Xamarin.ios native app? 如何使用故事板添加自定义数据源类 - How to add custom data source class using storyboard 如果没有Storyboard,如何初始化自定义ViewController? - How do I initialize a custom ViewController when there's no Storyboard? 在故事板中,如何制作用于多个控制器的自定义单元格? - In a storyboard, how do I make a custom cell for use with multiple controllers? 如何创建可重用的自定义控件并在情节提要中使用它? - How do I create a reusable custom control and use it in storyboard? 如何向故事板中创建的UI添加功能? - How do I add functionality to a UI made in storyboard? 如何使用Storyboard将页脚添加到UITableView? - How do I add a footer to a UITableView using Storyboard? 如何使用Storyboard将UISegmentedControl添加到UIToolbar? - How do I add a UISegmentedControl to my UIToolbar using Storyboard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM