swift - strokeThrough 属性与 iOS 13 不兼容
问题描述
我已使用此String
扩展程序将罢工添加到文本中
这是扩展名:
extension String{
func strikeThrough()->NSAttributedString{
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: self)
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0, attributeString.length))
return attributeString
}
在这里我如何使用UILabel
:
if isDone {
self.title?.attributedText = title.strikeThrough()
} else {
self.title?.attributedText = nil
self.title?.text = title
}
它在 iOS 12 中运行良好,但在 iOS 13 中,self.title?.attributedText = nil
不会删除删除线。在我的应用程序中,当在文本上添加罢工时,它将从列表中删除,但现在,它已被删除,但罢工将出现在其他文本上,这不应该发生。还有self.title?也不为零。
您能否建议我以任何方式strikeThrough
从文本中删除,当前的表单nil
不起作用。
太感谢了
解决方案
在我不想再显示的情况下,我通过将值设置为 0 来使其工作。
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: weightString)
//HACK we have to set strikethrough to 0 for ios 13 or it won't remove the strike even if setting the attributed text to nil
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: 0, range: NSMakeRange(0, attributeString.length))
cell.weightLabel.attributedText = attributeString))
推荐阅读
- python - 在 Python 3 中使用 f2py 时出现错误“架构 i386 的未定义符号”
- facebook - Facebook 应用审核要求
- wpf - WPF 单选按钮背景颜色
- firebase - 使用 Firebase 时如何管理在现有对象上添加新属性?
- php - Facebook 返回要下载的图片 URL
- mongodb - Mongo在数组字段上错误排序?
- python-3.x - 具有用于节点和树的单独类的二叉树实现
- nosql - Orientdb sql,从多个表中选择
- reactjs - 在 React 中的 style={{}} 中连接 props 和静态值
- spring - 将 spring.jackson.serialization.write-dates-as-timestamps & date-format 设置为全局 ISO1806