问题描述
如果应用范围不是整个字符串范围,则不会呈现作为属性添加到 NSMutableAttributedString
实例的删除线(单、双...).
A strikethrough (single, double, ...) added as attribute to an instance of NSMutableAttributedString
is not rendered if the apply range is not the whole string range.
使用 addAttribute(_ name: String, value: Any, range: NSRange)
, insert(_ attrString: NSAttributedString, at loc: Int)
, append(_attrString: NSAttributedString)
, ...
This happens using addAttribute(_ name: String, value: Any, range: NSRange)
, insert(_ attrString: NSAttributedString, at loc: Int)
, append(_ attrString: NSAttributedString)
, ...
在早期的 iOS 10.3 测试版中被 Apple 破坏,在 10.3 最终版中未修复.
Broken by Apple in early iOS 10.3 betas, and not fixed in 10.3 final.
信用:https://openradar.appspot.com/31034683
推荐答案
添加一个 NSBaselineOffsetAttributeName
,如解释 here,属性字符串带回删除线.覆盖 drawText:in:
可能会很慢,尤其是在 Collection View 或 Table View Cells 上.
Adding a NSBaselineOffsetAttributeName
, as explained here, to the attributed string brings back the strikethrough line. Overriding drawText:in:
can be slow especially on Collection View or Table View Cells.
这篇关于iOS 10.3:如果应用于 NSMutableAttributedString 的子范围,则不会呈现 NSStrikethroughStyleAttributeName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!