简体   繁体   中英

How to use xib file as custom view in storyboard

I use xib to create my custom view, and i bounded it with the same name .h .m file. I set the custom view class to UIView's class in storyboard , but it didn't work.

my custom view

在此处输入图片说明

I drag a UIView

在此处输入图片说明

Step 1 :

Create a Xib (your View) file, then create your.h and .m files,

If you already have a viewcontroller that will use the xib: implements everything in it.

Step 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.

Step 3 :

import your xib class in your.h file

Now you can create IBOUTLET in your.h file.

Step 4 :

To get the xib in your.m just write something like this -->

in viewDidLoad:(or everywhere you need it)

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. Then create your custom interface/functionality methods to work easy on it.

hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM