UITableView tableheaderview AutoLayout Automatic height calculation

Source: Internet
Author: User

1. Code mode

// Test Code @interface Viewcontroller () <UITableViewDataSource>*TableView; @property (Strong, nonatomic)  * headerlable, @property (Strong, nonatomic)   *Headerview; @end

Auto layout is able to calculate the correct interface is required to be constrained sufficiently
self.headerlable = [UILabelNew]; Self.headerLable.numberOfLines=0; Self.headerview= [UIViewNew]; [Self.headerview addSubview:self.headerLable]; [Self.headerlable mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.edges.mas_equalTo (Self.headerview). Valueoffset ([Nsvalue valuewithuiedgeinsets:uiedgeinsetsmake (Ten,Ten,Ten,Ten)]); }]; Self.tableView.tableHeaderView=Self.headerview; [Self.headerview mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.width.mas_equalTo (self.view.mas_width); }]; Self.headerLable.text=@"test Text Test text Test text test textual testing text Test text Test text Test text Test text Test text test texts";
[Self.tableView.tableHeaderView layoutifneeded]; Self.tableView.tableHeaderView= Self.headerview;

? 1. When modifying the TableView Tableheaderview interface, the interface does not refresh in time and can be called manually layoutifneeded the view height is the ideal height

2.tableViewHeader height changes, the interface can not be refreshed in time need to re-set the Headerview to TableView Tableheaderview, the interface can be displayed correctly

3. Of course, when using auto layout, the constraints must be sufficient to calculate the correct height oh ^ ^

UITableView tableheaderview AutoLayout Automatic height calculation

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.