本文介绍了滑动即可将删除线添加到tableview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在滑动时我很难在行文本上删除线(例如,左).
我正在使用tableview方法leadingSwipeActionsConfigurationForRowAt
,但是在滑动时找不到删除线文本的解决方案.
到目前为止,已滑动"行实际上已被删除.
I've got a problem to strikethrough over the row text while swiping (E.G. left).
I'm using the tableview method leadingSwipeActionsConfigurationForRowAt
, but I can't find the solution to strikethrough text while swiping.
As of now, the "swiped" row actually gets deleted.
我要做什么:
代码:
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
}
推荐答案
我找到了一些解决方案.也许它可以帮助某人.这是代码:
I found some solution. Maybe it helps someone. Here is the code:
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 attributedText
There is a .gif with the exampleattributedText
这篇关于滑动即可将删除线添加到tableview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!