1.Command+N创建UIView文件

2.Command+N创建一个和上面UIView文件同名的xib文件


3.加载xib文件
第一种方法:addSubview到viewController的视图上
NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:nil options:nil];
if (views.count > 0) {
UIView *view = views[0];
view.backgroundColor = [UIColor yellowColor];
[self.view addSubview:view];
view.center = self.view.center;
}
效果如下

第二种方法:在storyboard中拖一个View并设置类名为我们创建的CustomView

效果如下

网友评论