HI has a custom view class that loads and fits into my main view using the following code. The reason is because I want to fill it with different content, and not create a view in the code every time, if I create a custom class, I can reuse it in a loop, etc., I got this to work very well in the code , i.e. put stickers on buttons, etc.
But instead of drawing code, I thought that if I create a new kind of user interface, then I will visually create my own text fields, labels and buttons on this view.
Then connect it to my custom class.
Bu is where I had a problem, how to connect this kind of xib view file so that it becomes visible when it was placed in my code. I assigned a custom class attribute in the xib file to my custom file, but what else am I missing?
.h file:
.m file:
#import "blogView.h" @implementation blogView - (id)init { self = [super initWithFrame:CGRectMake(0, 0, 478, 220)]; if (self != nil) { NSLog(@"Blog View loaded"); self.backgroundColor = [UIColor yellowColor]; UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 400, 40)]; [titleLbl setText:@"This is the Title"]; [self addSubview:titleLbl]; } return self; } @end
my xib file has the same blogView.xib name as the user interface.
In my main view controller and in ViewDidLoad I have
blogView *blogItem = [[blogView alloc]init]; [self.view addSubview:blogItem];
When I run this, everything works fine, but I would like to link the .xib file to save time, etc. Thanks