1

在滑动(EG 左)时,我在行文本上划线时遇到问题。
我正在使用 tableview 方法leadingSwipeActionsConfigurationForRowAt,但在滑动时找不到删除线文本的解决方案。
截至目前,“刷卡”行实际上已被删除。

我想要做什么:

举例我想要的

代码:

override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let complete = completeAction(at: indexPath)
    return UISwipeActionsConfiguration(actions: [complete])
}

func completeAction(at indexPath: IndexPath) -> UIContextualAction {
    let action = UIContextualAction(style: .destructive, title: "Complete") { (action, view, completion) in
        self.kind.remove(at: indexPath.row)
        self.tableView.deleteRows(at: [indexPath], with: .fade)
                completion(true)
        if let context = (UIApplication.shared.delegate as? AppDelegate)?.coreDataStack.persistentContainer.viewContext {
            let objectToDelete = self.fetchResultsController.object(at: indexPath)
                    context.delete(objectToDelete)
            do {
                try context.save()
            } catch {
                print(error.localizedDescription)
            }
        }
    }
    return action
}
4

1 回答 1

0

我找到了一些解决方案。也许它可以帮助某人。这是代码:

func strikeThroughText (_ text:String) -> NSAttributedString {
        let attributeString: NSMutableAttributedString =  NSMutableAttributedString(string: text)
        attributeString.addAttribute(NSAttributedStringKey.strikethroughStyle, value: 1, range: NSMakeRange(0, attributeString.length))
        return attributeString
    }

UIView.animate(withDuration: 0.1, animations: {
                cell.transform = cell.transform.scaledBy(x: 1.5, y: 1.5)
            }, completion: { (success) in
                UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.5, options: .curveEaseOut, animations: {
                    cell.transform = CGAffineTransform.identity
                }, completion: nil)
            })

有一个带有示例 属性文本的 .gif

于 2018-05-14T19:10:22.310 回答