简体   繁体   中英

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

在此处输入图像描述

Storyboard Design

在此处输入图像描述

Disabled Constraints For UIView

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM