1

在此处输入图像描述

谁能解释如何解决这个问题?

这是它现在在 iPhone X (iOS 12.4) 上向我展示的内容

这是我下面的代码

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    guard let account = accounts?[indexPath.row] else { return nil }

    getAndSetAmountConstraint(from: account)

    let editAction = UIContextualAction(style: .normal, title: nil) { [weak self] (_, _, completionHandler) in
        self?.showEditAlertViewWith(account: account)
        completionHandler(true)
    }
    let deleteAction = UIContextualAction(style: .normal, title: nil) { [weak self] (_, _, completionHandler) in
        self?.removeRow(at: indexPath)
        completionHandler(true)
    }

    editAction.image = UIImage(named: "edit")
    deleteAction.image = UIImage(named: "delete")
    editAction.backgroundColor = .lightGray
    deleteAction.backgroundColor = .lightGray

    let actions = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
    return actions
}
4

1 回答 1

3
    class ImageWithoutRender: UIImage {
    override func withRenderingMode(_ renderingMode: UIImage.RenderingMode) -> UIImage {
        return self
    }
}

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    guard let account = accounts?[indexPath.row] else { return nil }

    getAndSetAmountConstraint(from: account)

    let editAction = UIContextualAction(style: .normal, title: nil) { [weak self] (_, _, completionHandler) in
        self?.showEditAlertViewWith(account: account)
        completionHandler(true)
    }
    let deleteAction = UIContextualAction(style: .normal, title: nil) { [weak self] (_, _, completionHandler) in
        self?.removeRow(at: indexPath)
        completionHandler(true)
    }

    if let cgImageEdit =  UIImage(named: "edit")?.cgImage {
        editAction.image = ImageWithoutRender(cgImage: cgImageEdit, scale: UIScreen.main.nativeScale, orientation: .up)
    }
    
    if let cgImageDelete =  UIImage(named: "delete")?.cgImage {
        deleteAction.image = ImageWithoutRender(cgImage: cgImageDelete, scale: UIScreen.main.nativeScale, orientation: .up)
    }
    editAction.backgroundColor = .lightGray
    deleteAction.backgroundColor = .lightGray

    let actions = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
    return actions
}

尝试这个

于 2021-02-20T09:49:19.987 回答