簡體   English   中英

如何獲取UITableView的最后一個單元格分隔符占整個長度?

[英]How to get the last cell separator of a UITableView take the full length?

我想讓UITableView的最后一個單元格分隔符占據整個長度

在此處輸入圖片說明

我嘗試了這段代碼,但它沒有任何改變:

// in UITableViewDelegate 
func tableView(tableView: UITableView, willDisplayCell cell:UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

     cell.separatorInset = UIEdgeInsetsZero
     cell.layoutMargins = UIEdgeInsetsZero
     cell.preservesSuperviewLayoutMargins = false
}

//UITableViewDataSource
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

     tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
     tableView.separatorInset = UIEdgeInsetsZero 
}

這一切都與preservesSuperviewLayoutMargins屬性有關。 假設您的表格視圖有1個部分和20行。 那你會說:

if indexPath.row == 19 {
    cell.separatorInset = UIEdgeInsetsZero
    cell.layoutMargins = UIEdgeInsetsZero
    cell.preservesSuperviewLayoutMargins = false
} else {
    cell.preservesSuperviewLayoutMargins = true
}

您可以看到它有效:

在此處輸入圖片說明

暫無
暫無

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

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