We often need to use the custom view in the project, and the Xib layout is more concise, then how to load a custom xib, the online method is a lot of, because too much, I often confuse, so summarize one of the use, if later use to the other in the Supplement O (∩_∩) o ~~
1. Create afile that inherits the UI view and Xib, named the same
2. Set the view owner's class
3. Attribute to view Association
The. m file inside the view loads Xib:
-(void) awakefromnib {
[[nsbundlemainbundle]loadnibnamed:@ ' TestView 'owner:Selfoptions: Nil];
[selfaddsubview: Self. TestView];
}
-(instancetype) initWithFrame: (cgrect) frame
{
Self = [superInitwithframe:frame];
if (self) {
[[nsbundlemainbundle]loadnibnamed:@ ' TestView 'owner:Selfoptions: Nil];
[selfaddsubview: Self. TestView];
}
return self;
}
4. Use a custom view inside the controller
-(ibaction) popviewaction: (UIButton *) Sender {
_myview = [[testviewalloc]initwithframe:CGRectMake (0,kscreenheight- 320, )];
[Self. Viewaddsubview:_myview];
}
ios--controller loads the xib of custom view