1
votes

I have a custom UIView and xib called DialPad and I'm trying to use this object in my storyboard, but the custom DialPad isn't being add as a subview with the buttons

my custom DialPad :UIView

@implementation DialPad


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

my custom xib called DialPad enter image description here

and my view controllers look like this

#import <UIKit/UIKit.h>
#import "DialPad.h"

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIView *dial;
@end


#import "ViewController.h"
@interface ViewController ()
{
    DialPad  *d;
}
@end

@implementation ViewController

- (void)viewDidLoad 
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    d = [[DialPad alloc] initWithFrame:self.dial.frame];

    [self.dial addSubview:d];
}    
@end

and my storyboard enter image description here

but the border around the view looks strange

enter image description here

#import "DialPad.h"
#import <QuartzCore/QuartzCore.h>

@implementation DialPad

- (void)drawRect:(CGRect)rect
{
    // Drawing code
    self.layer.borderColor = [UIColor redColor].CGColor;
    self.layer.borderWidth = 1;
}
@end

enter image description here

1

1 Answers

2
votes

For loading a view from xib file, you should do this:

d = [[[NSBundle mainBundle] loadNibNamed:@"DialPad" owner:nil options:nil]
                 firstObject];
[self.dial addSubview:d];

Border: try to add border code in - (void)awakeFromNib