Can't set constraints of UItableView's tableHeaderView height by autolayout in Storyboard

这一生的挚爱 提交于 2019-12-06 05:29:02

问题


I want the screen only shows one tableveiwCell with headerView.I added a UIView as header view on the top of UITableView with "Size classes" in storyboard(Just drag a UIView on the top of the UITableView), it can compatible with all devices screen size in this way.

So change header view's height by constraints is what i want to. but when i try to do that, i cant set constraints for the headerView(Xocde doesn't enable me select any constrains in storyboard, Image 2 below). As below.

Any ideas, thanks!

The project code is here: https://github.com/williamhqs/AutoLayoutTableViewHeaderView

EIDT: Seems it still can't be set in storyboard.

Then i will have to change table header view's frame by code then update constraints.

UIView *v = self.tableView.tableHeaderView;
CGRect fr = v.frame;
fr.size.height = [UIScreen mainScreen].bounds.size.height -100;
v.frame = fr;
[self.tableView updateConstraintsIfNeeded];

回答1:


i think that UIView doesn't have any superview So that it is not showing the constraints for view.




回答2:


Then i will have to change table header view's frame by code then update constraints.

UIView *v = self.tableView.tableHeaderView;
CGRect fr = v.frame;
fr.size.height = [UIScreen mainScreen].bounds.size.height -100;
v.frame = fr;
[self.tableView updateConstraintsIfNeeded];


来源:https://stackoverflow.com/questions/27330165/cant-set-constraints-of-uitableviews-tableheaderview-height-by-autolayout-in-s

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!