Tableheaderview Masonry
UIView *headview =[uiview New];
Headview.backgroundcolor = [Uicolor Yellowcolor];
UIView *view1 =[uiview New];
View1.backgroundcolor =[uicolor Redcolor];
[Headview Addsubview:view1]; [View1 makeconstraints:^ (Masconstraintmaker *make)
{Make.top.left.equalTo (10);
Make.right.equalTo (-10);
Make.height.equalTo (100);
}];
UIView *view2 =[uiview New];
View2.backgroundcolor =[uicolor Blackcolor];
Uilabel *label = [[Uilabel alloc] init];
[Label setnumberoflines:0]; Calculates the preferredmaxlayoutwidth value of the Uilabel, which must be set for multiple rows, or the system cannot determine the width of the label (* * * * * * * *) Label.preferredmaxlayoutwidth =
ULMainScreenWidth-20;
[Label Setbackgroundcolor:[uicolor Greencolor]]; [Label settext:@ "after this wrote in 7.1 directly error auto Layout still required after executing-layoutsubviews. UITableView ' s implementation of-layoutsubviews needs to call super. In 8 there is no error, but Headview did not show, according to the literal meaning of the parent view to the layout, I think it should be tableheaderview in the tableview inside the system should have its own layout, in the outside set up the words on the conflict, and thenError, do not know whether this understanding is correct. \ n later StackOverflow looked at some questions and answers, basically set up a good headview, according to the Headview subview AutoLayout calculate the height, and then the height of the assignment to Headview.
Below is the Headview above has 2 sub views, height each 100 "];
[View2 Addsubview:label]; [Label makeconstraints:^ (Masconstraintmaker *make)
{make.top.left.right.equalTo (0);
Make.bottom.equalTo (VIEW2);
}];
[Headview Addsubview:view2]; [View2 makeconstraints:^ (Masconstraintmaker *make)
{Make.top.equalTo (View1.bottom). Offset (10);
Make.left.right.equalTo (View1);
Make.bottom.equalTo (Headview). Offset (-10);
}];
CGFloat height = [Headview systemlayoutsizefittingsize:uilayoutfittingcompressedsize].height;
CGRect frame = headview.frame;
Frame.size.height = height;
Headview.frame =frame; Tableview.tableheaderview = Headview;
From: http://qcliwei.com/2015/08/02/tableHeaderView-autolayout/
http://tutuge.me/2015/08/08/autolayout-example-with-masonry2/