gpt4 book ai didi

ios - tableHeaderView 未正确调整大小

转载 作者:行者123 更新时间:2023-11-28 08:30:02 26 4
gpt4 key购买 nike

我正在使用带有自定义 tableHeaderViewUITableView

在我的 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

它将所有内容对齐到左上边缘。

编辑: View 的设置就像它们放在 Storyboard 中一样

edit2:截图

它应该是这样的:

enter image description here

这是它的样子

enter image description here

最佳答案

您可以在 UITableViewDelegate 方法 tableView:heightForHeaderInSection: 中设置表 hader View 。当然,使用 NSLayoutConstraint 来定位您的元素 ( good tutorial )。

关于ios - tableHeaderView 未正确调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39039258/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com