我注意到有几种构造NSRange
的方法
let range = NSRange(location: 0, length: attributedString.length)
attributedString.addAttribute(..., range: range)
和
let range = NSRange(location: 0, length: attributedString.string.utf16.count)
attributedString.addAttribute(..., range: range)
我在想,attributedString.length
总是等同于attributedString.string.utf16.count
吗?
到目前为止,我无法找到任何情况下他们是不同的。
当他们不在的时候,有什么情况吗?
发布于 2022-09-03 05:18:30
是的,是一样的。根据苹果公司的文件,NSAttributedString.length是接收器中UTF-16码单元的数量。
然后
attributedString.length =属性字符串.utf16.count
https://developer.apple.com/documentation/foundation/nsattributedstring/1418432-length
https://stackoverflow.com/questions/73589458
复制相似问题