1.要在view中从上到下设置好各个约束
[self.header setNeedsLayout];
[self.header layoutIfNeeded];
CGFloat height = [self.header systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
CGRect headerFrame = self.header.frame;
headerFrame.size.height = height;
self.header.frame = headerFrame;
self.tableView.tableHeaderView = self.header;
3.自定义的header中
- (void)layoutSubviews{
[super layoutSubviews];
self.contenLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.contenLabel.frame);
}
4.如果视图中有hidden的布局文件,在不显示的时候 要remove,避免影响自动布局