Xib的加载
方法1
NSArray *views = [[NSBundle mainBundle] loadNibNamed:@“xib文件名” owner:nil options:nil]
NSArray *views=[[NSBundle mainBundle]loadNibNamed:@"carView" owner:nil options:nil];
UIView *v1=[views lastObject];
[self.view addSubview:v1];
v1.frame=CGRectMake(0, 0, 150, 80);//注意这里只能改变位置,不能改变大小
方法2
UINib *nib = [UINib nibWithNibName:@“xib文件名” bundle:nil];
NSArray *views = [nib instantiateWithOwner:nil options:nil];
UINib *nib=[UINib nibWithNibName:@"carView" bundle:nil];
NSArray *views=[nib instantiateWithOwner:nil options:nil];
UIView *v1=[views lastObject];
[self.view addSubview:v1];
v1.frame=CGRectMake(200, 200, 100, 100);
加载多个UIView
先把xib资源读取到数组,然后在加载
NSArray *views=[[NSBundle mainBundle]loadNibNamed:@"carView" owner:nil options:nil];
UIView *v1=[views firstObject];
[self.view addSubview:v1];
v1.frame=CGRectMake(200, 200, 100, 100);
UIView *v2=[views lastObject];
[self.view addSubview:v2];
v2.frame=CGRectMake(100, 100, 100, 100);