![](/img/trans.png)
[英]iOS7 last cell in UITableView section forces full width separator
[英]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.