Reputation: 173
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
Storyboard Design
Disabled Constraints For UIView
Upvotes: 1
Views: 300
Reputation: 5451
Constraints
is not working with table header view. you can set table header using custom view and update its frame
Set a custom view
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
}
}
Upvotes: 2