簡體   English   中英

在UITableView頁腳視圖中放置自定義UILabel

[英]Positioning a custom UILabel inside a UITableView footer view

我有一個UITableViewController,我通過設置footerView

self.tableView.tableFooterView = FooterView()

在類FooterView中,我通過添加標簽

self.addSubView(label)

我注意到以下內容。

  • footerView位於tableView的頂部
  • 標簽在頁腳視圖中

我的問題是

  • 當我將footerView的Frame設置為(0,0,100,100)時,它似乎在tableView上重疊。 如何將頁腳放置在tableView的底部?

  • 通過頁腳的addSubView()添加標簽時。 它的位置與footerView或tableView相關嗎?

  • FooterView的默認高度為44。如果未將footerView的高度設置為更高,然后將標簽的高度設置為100,則該標簽會重疊。

  • 它與footerView一起定位。

您可以使用UITableViewDelegate方法設置footerView的高度。下面是實現所需功能的方法。頁腳視圖僅位於表格視圖的底部。

 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 5
}

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView .dequeueReusableCellWithIdentifier("cellIdentifier") as! UITableViewCell
        cell.textLabel?.text = "trial"
        return cell
    }

func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    if section == 1{
        return 100
    }
        return 0

}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 2 //The number you needed + 1
}

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    if section == 1{

        return FooterView()
    }
    return nil
}

刪除這行

self.tableView.tableFooterView = FooterView()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM