我正在使用UITableView
与自定义tableHeaderView
在我viewDidLayoutSubviews
我正在使用正常运行的代码:
let bounds = UIScreen.mainScreen().bounds
imageSliderVC.view.frame = CGRectMake(0, 0, bounds.width, bounds.width)
layerView.frame = CGRectMake(0, 0, bounds.width, bounds.width)
noButton = constructNopeButton()
yesButton = constructLikedButton()
buttonOptionsApply()
nameLbl.frame = CGRectMake(20, layerView.frame.maxY + 20, bounds.width-40, 20)
nameLbl.makeNameLabelFormat()
hashtagLbl.frame = CGRectMake(20, nameLbl.frame.maxY + 5, bounds.width-40, layerView.frame.width/3.66)
hashtagLbl.makeHashtagFormat()
seperatorLbl.frame = CGRectMake(20, hashtagLbl.frame.maxY + 15, bounds.width-40, 1)
groupsLbl.frame = CGRectMake(20, seperatorLbl.frame.maxY + 15, 30, 20)
groupsLbl.makeNameLabelFormat()
groupsLbl.sizeToFit()
groupsCountLbl.frame = CGRectMake(groupsLbl.frame.maxX + 5, seperatorLbl.frame.maxY + 15 , 40, 20)
groupsCountLbl.sizeToFit()
headerView.frame = CGRectMake(0, 0, bounds.width, groupsCountLbl.frame.maxY)
table.tableHeaderView = headerView
不使用headerView,一切都很好地对齐。 该表与autoLayout一起使用 - 将表固定到所有边缘。
知道为什么会这样吗?尝试使用
headerView.translatesAutoresizingMaskIntoConstraints = false
它将所有内容与左上边缘对齐。
修改 视图设置就像放在故事板中一样
edit2:屏幕截图
应该看起来像这样:
这就是它的样子
答案 0 :(得分:0)
您可以在UITableViewDelegate方法tableView:heightForHeaderInSection:
中设置表格黑客视图。当然,使用NSLayoutConstraint来定位元素(good tutorial)。