1

I am using a UITableView with a custom tableHeaderView

In my viewDidLayoutSubviews I am using properly working code like this:

 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

Without using the headerView everything aligns nicely. the table is used with autoLayout - pinning the table to all the edges.

Any idea why this is happening? tried using

        headerView.translatesAutoresizingMaskIntoConstraints = false

it aligns everything to the left top edge.

edit: The views are set like as they are put in storyboard

edit2: Screenshots

it is supposed to look like this:

enter image description here

This is what it looks like

enter image description here

JVS
  • 2,592
  • 3
  • 19
  • 31

1 Answers1

0

You can set table hader view in UITableViewDelegate method tableView:heightForHeaderInSection:. And, of course, use NSLayoutConstraint's to locate you elements (good tutorial).

Srj0x0
  • 458
  • 3
  • 12