Tableheaderview's Masonry

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.