Ios tableHeaderView不';无法正确调整大小
我正在将Ios tableHeaderView不';无法正确调整大小,ios,swift,uitableview,cgrectmake,Ios,Swift,Uitableview,Cgrectmake,我正在将UITableView与自定义tableHeaderView 在我的viewdilayoutsubviews中,我使用的代码如下: let bounds = UIScreen.mainScreen().bounds imageSliderVC.view.frame = CGRectMake(0, 0, bounds.width, bounds.width) layerView.frame = CGRectMake(0, 0, bounds.width, bounds.
UITableView
与自定义tableHeaderView
在我的viewdilayoutsubviews
中,我使用的代码如下:
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,一切都很好地对齐。
表格与自动布局一起使用-将表格固定到所有边缘
知道为什么会这样吗?试用
headerView.translatesAutoresizingMaskIntoConstraints = false
它将所有内容与左上边缘对齐
编辑:
视图的设置与在故事板中的设置相同
edit2:屏幕截图
应该是这样的:
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
这就是它看起来的样子
您可以在UITableViewDelegate方法中设置表格hader视图
表格视图:头部高度部分:
。当然,还可以使用NSLayoutConstraint来定位元素()。您可以在UITableViewDelegate方法中设置table hader视图tableView:heightForHeaderInSection:
。当然,还可以使用NSLayoutConstraint定位元素()。输出是什么?显示屏幕截图。你能发布你的viewForHeaderInSection方法吗?我没有使用这个方法。我来看看。在我的示例中,它应该是什么样子的?好吧,你的问题是关于标题的,我认为你正在子类化一个视图并添加你的自定义行为,但是,也许不是这样,所以你可以发布你的viewController代码来尝试帮助?输出是什么?显示屏幕截图。你能发布你的viewForHeaderInSection方法吗?我没有使用这个方法。我来看看。在我的示例中,它应该是什么样子的?好吧,你的问题是关于标题的,我认为你正在子类化一个视图并添加你的自定义行为,但是,也许不是这样,所以你可以发布你的viewController代码来尝试帮助?