首先新建一個空的xib文件:
將size改為freedom:
然后在xib中自定義視圖(添加自己想要的其它視圖):
要寫好約束, 創建一個繼承uiview的類和他關聯,然后就可以調用了.
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.
//獲得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).
// 得到最后一個view
HeadView *headView = [nibContents lastObject]; headView.frame = CGRectMake(0, 0, 300, 200); //headView.backgroundColor = [UIColor blueColor]; _tableView.tableHeaderView = headView; }