首先新建一个空的xib文件:
然后在xib中自定义视图(添加自己想要的其它视图):
要写好约束, 创建一个继承uiview的类和他关联,然后就可以调用了.
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"HeadView" owner:nil options:nil]; // Find the view among nib contents (not too hard assuming there is only one view in it). HeadView *headView = [nibContents lastObject]; headView.frame = CGRectMake(0, 0, 300, 200); //headView.backgroundColor = [UIColor blueColor]; _tableView.tableHeaderView = headView; }
时间: 2024-10-27 13:43:10