1

In my case, I have to add UIView in top of the Tableview but it should be inside Tableview because of scrolling. Here, I drag and dropped UIView on topside tableview. Now, some scenario I need to increase and reduce height of the UIView. I tried to add constraints but its not available. How to achieve this by codebase?

Tableview with UIView Storyboard Hierarchy

enter image description here

Storyboard Design

enter image description here

Disabled Constraints For UIView

enter image description here

myapp store
  • 173
  • 11

1 Answers1

2

Constraints is not working with table header view. you can set table header using custom view and update its frame

Set a custom view

enter image description here

Set table header and update it's frame

class ViewController: UIViewController {

    @IBOutlet var tableView: UITableView!

    @IBOutlet var tableHeader: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        loadHeader()
    }

    func loadHeader() {
        tableHeader.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 300)
        tableView.tableHeaderView = tableHeader
    }
}
Harshal Valanda
  • 5,331
  • 26
  • 63