Open TouchGuoGuo opened 1 year ago
等价于调用
func setAttributes(_ attrs: [NSAttributedString.Key : Any]?, range: NSRange)
你可以用
public mutating func add(attributes: [Attribute], range: NSRange) {
这个库,按照作者的回复,应该是基于 NSAttributedString
,所以在确定range
的时候,应该先将Swift.String
转化成NSString
。比如:
let length = "🤔".count
let range = NSRange(location: 0, length: length)
应该改成:
let length = ("🤔" as NSString).length
let range = NSRange(location: 0, length: length)
我脱机敲的,不知道准不准确。
或者可以用"🤔".utf8.count 等于 ("🤔" as NSString).length
使用该方法public mutating func set(attributes: [Attribute], range: NSRange)设置字体颜色 在多个range的情况下只有最后一个生效