I’m having troubles with displaying label within the tableHeaderView. The textual content will get pushed out of the view to the highest. After checking the tableHeaderView dynamic top setups, it appears that evidently I need to’ve messed one thing up with the constrains. Are you able to please inform me why is my tableHeaderView doesn’t regulate to the dimensions of the label in it. Here is the code:
override func viewDidLoad() {
tremendous.viewDidLoad()
secondTableView.delegate = self
secondTableView.dataSource = self
let tableHeader = UIView()
secondTableView.tableHeaderView = tableHeader
let dimension = tableHeader.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
let top = dimension.top
let width = dimension.width
tableHeader.body = CGRectMake(0, 0, width, top)
tableHeader.translatesAutoresizingMaskIntoConstraints = true
tableHeader.backgroundColor = .systemOrange
let labelOne = UILabel(body: tableHeader.bounds)
labelOne.textual content = "USER:"
tableHeader.addSubview(labelOne)
labelOne.translatesAutoresizingMaskIntoConstraints = false
labelOne.centerXAnchor.constraint(equalTo: tableHeader.centerXAnchor).isActive = true
let labelTwo = UILabel(body: tableHeader.bounds)
labelTwo.textual content = "Inherited textual content right here: (insertionText)"
tableHeader.addSubview(labelTwo)
labelTwo.numberOfLines = 0
labelTwo.textAlignment = .heart
labelTwo.translatesAutoresizingMaskIntoConstraints = false
labelTwo.topAnchor.constraint(equalTo: labelOne.bottomAnchor, fixed: 0).isActive = true
labelTwo.leadingAnchor.constraint(equalTo: tableHeader.layoutMarginsGuide.leadingAnchor, fixed: 0).isActive = true
labelTwo.trailingAnchor.constraint(equalTo: tableHeader.layoutMarginsGuide.trailingAnchor, fixed: 0).isActive = true
labelTwo.bottomAnchor.constraint(equalTo: tableHeader.bottomAnchor, fixed: 11).isActive = true
}