[英]How to use xib file as custom view in storyboard
Step 1 : 第1步 :
Create a Xib (your View) file, then create your.h and .m files, 创建一个Xib(您的View)文件,然后创建your.h和.m文件,
If you already have a viewcontroller that will use the xib: implements everything in it. 如果您已经有一个将使用xib的viewcontroller:在其中实现所有功能。
Step 2 : 第2步 :
Open your Xib file, in the interface builder you will find on the left : File's owner, select it and then, on the right in the identity inspector tab, add your custom class. 打开Xib文件,在界面生成器中,您将在左侧找到:File的所有者,将其选中,然后在右侧的Identity inspector选项卡中添加您的自定义类。
Step 3 : 第三步:
import your xib class in your.h file 将xib类导入到your.h文件中
Now you can create IBOUTLET in your.h file. 现在,您可以在.h文件中创建IBOUTLET。
Step 4 : 第四步 :
To get the xib in your.m just write something like this --> 要将xib放入your.m中,只需编写如下内容->
in viewDidLoad:(or everywhere you need it) 在viewDidLoad :(或您需要的任何地方)
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"RunningMode_VC_Interface" owner:self options:nil];
runningViewXib = [subviewArray objectAtIndex:0];
runningViewXib.frame = self.view.frame;
[self.view addSubview:runningViewXib];
You will now add your custom view to your viewcontroller. 现在,您将自定义视图添加到您的viewcontroller。 Then create your custom interface/functionality methods to work easy on it. 然后创建您的自定义界面/功能方法以使其易于使用。
hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.