简体   繁体   English

如何设置UITableView _UISwipeToDeletePlaceholderCell的颜色

[英]How to set color of UITableView _UISwipeToDeletePlaceholderCell

I have UITableView with a backgroundView set to a UIImageView. 我有UITableView与backgroundView设置为UIImageView。 The UIImageView uses an image with gradient pattern. UIImageView使用带有渐变图案的图像。

let imageView = UIImageView.init(frame: tableView.frame)
imageView.image = UIImage.init(named: "background")
tableView.backgroundView = imageView

When I delete rows, the table automatically inserts a white row. 当我删除行时,表格会自动插入白色行。 When I pause the app with Xcode to view the drawn components, it shows that it's a _UISwipeToDeletePlaceholderCell. 当我使用Xcode暂停应用程序以查看绘制的组件时,它表明它是_UISwipeToDeletePlaceholderCell。

How do I get the _UISwipeToDeletePlaceholderCell to use a clear background color? 如何获得_UISwipeToDeletePlaceholderCell以使用清晰的背景色?

I have tried setting all components in the tableview to use clear colors but that didn't seem to work 我尝试将tableview中的所有组件设置为使用清晰的颜色,但这似乎不起作用

view.backgroundColor = UIColor.clear
tableView.backgroundColor = UIColor.clear
tableView.separatorColor = UIColor.clear
tableView.sectionIndexColor = UIColor.clear
tableView.sectionIndexBackgroundColor = UIColor.clear
tableView.sectionIndexTrackingBackgroundColor = UIColor.clear

Here is how I am deleting: 这是我要删除的方式:

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        // Delete the row from the data source
        self.budget = budget.removingTransaction(at: indexPath.row-1)
        tableView.deleteRows(at: [indexPath], with: .none)
    }
}

表格检视

行删除

_UISwipeToDeletePlaceholderCell

I hope it's due to updating table after delete your row. 我希望这是由于删除行后更新表所致。 Try this code:- 试试这个代码:

override func tableView(_ tableView: UITableView, commit editingStyle: 
UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        // Delete the row from the data source
        self.budget = budget.removingTransaction(at: indexPath.row-1)
        tableView.beginUpdates()
        tableView.deleteRows(at: [indexPath], with: .none)
        tableView.endUpdates()
    }
}

I hope it will help you, Thank you. 希望对您有所帮助,谢谢。

 func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        dataSource.remove(at: indexPath.row)
        tableView.deleteRows(at: [indexPath], with: .automatic)
        clearWhiteBackgroundWhenDelete()
    }
}

func clearWhiteBackgroundWhenDelete() {
    if let whiteBackgroudViewClass = NSClassFromString("_UISwipeToDeletePlaceholderCell") {
       _ = tableView.subviews.map { if $0.isKind(of: whiteBackgroudViewClass) { $0.backgroundColor = .clear } }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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