1

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

enter image description here

I drag a UIView

enter image description here

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
acethan
  • 71
  • 1
  • 6

1 Answers1

1

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.