gpt4 book ai didi

ios - swift 4 删除删除线

转载 作者:行者123 更新时间:2023-11-30 11:25:22 28 4
gpt4 key购买 nike

我点击该行会有删除线,点击一次后我希望去掉删除线

有完成度默认值为false

let newList = List(名称: 名称, 完成: false)

我尝试删除删除线cell.listName.attributedText = nil,但它会随着我的文字消失

func completeList(_ indexPath: IndexPath) {
let lists = self.lists[indexPath.row]
self.lists[indexPath.row] = lists
if let cell = listTableView.cellForRow(at: indexPath) as? ListTableViewCell {
cell.listName.attributedText = strikeThroughText(lists.name!)
}
}

// 刪除線
func strikeThroughText(_ text: String) -> NSAttributedString {
let attributeString = NSMutableAttributedString(string: text)
attributeString.addAttribute(NSAttributedStringKey.strikethroughStyle, value: 2, range: NSMakeRange(0, attributeString.length))
attributeString.addAttribute(NSAttributedStringKey.strikethroughColor, value:UIColor(red: 235, green: 86, blue: 87), range: NSMakeRange(0, attributeString.length))

return attributeString
}

TableView 委托(delegate)、数据源

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return lists.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let listCell = tableView.dequeueReusableCell(withIdentifier: "listCell") as! ListTableViewCell

let listItem = lists[indexPath.row]
listCell.listName.text = listItem.name

if listItem.completed {
listCell.listName.attributedText = strikeThroughText(listItem.name!)
}

listCell.backgroundColor = UIColor.clear
listCell.selectionStyle = .none
return listCell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
completeList(indexPath)

}

最佳答案

试试这个:

let attributeString = NSMutableAttributedString(string: text)
attributeString.removeAttribute(NSAttributedStringKey.strikethroughStyle, range: NSMakeRange(0, attributeString.length))
attributeString.removeAttribute(NSAttributedStringKey.strikethroughColor, range: NSMakeRange(0, attributeString.length))

关于ios - swift 4 删除删除线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50793691/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com