myapp store
myapp store

Reputation: 173

How to increase and decrease UIView height by codebase using Swift

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

Upvotes: 1

Views: 300

Answers (1)

Harshal Valanda
Harshal Valanda

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

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
    }
}

Upvotes: 2

Related Questions