另类布局

http://blog.it985.com/5121.html


http://blog.jobbole.com/61101/


func viewWillLayoutSubviews() {

super.viewWillLayoutSubviews()

if tableView.tableViewHeaderView == nil {

let header: MyHeaderView = MyHeaderView.createHeaderView()

header.setNeedsUpdateConstraints()

header.updateConstraintsIfNeeded()

header.frame = CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), CGFloat.max)

var newFrame = header.frame

header.setNeedsLayout()

header.layoutIfNeeded()

let newSize = header.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)

newFrame.size.height = newSize.height

header.frame = newFrame

self.tableView.tableHeaderView = header

}

}

你可能感兴趣的:(另类布局)