码迷,mamicode.com
首页 > 其他好文 > 详细

UITableView tableHeaderView autolayout自动计算高度

时间:2015-11-27 00:48:08      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

1.代码方式

//测试代码
@interface ViewController ()<UITableViewDataSource> 

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (strong, nonatomic)  UILabel *headerLable;

@property (strong, nonatomic)  UIView *headerView;

@end

 

 

    //Auto Layout能够计算出正确的界面的必要条件是约束充分
self.headerLable = [UILabel new]; self.headerLable.numberOfLines = 0; self.headerView = [UIView new]; [self.headerView addSubview:self.headerLable]; [self.headerLable mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self.headerView).valueOffset([NSValue valueWithUIEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)]); }]; self.tableView.tableHeaderView = self.headerView; [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(self.view.mas_width); }]; self.headerLable.text = @"测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本测试文本";
[self.tableView.tableHeaderView layoutIfNeeded]; self.tableView.tableHeaderView
= self.headerView;

? 1.修改tableView的tableHeaderView界面时,界面并不能及时刷新,可手动调用layoutIfNeeded 此时view高度为理想高度

    2.tableViewHeader高度变化时,界面也不能及时刷新 需要重新将headerView设置为tableView的tableHeaderView,界面即可正确显示了

    3.当然,使用auto layout时,约束条件必须充分 才能计算出正确高度哦^^

 

UITableView tableHeaderView autolayout自动计算高度

标签:

原文地址:http://www.cnblogs.com/binglin92/p/4993561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!