open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard
isActionEnabled,
let string = attributed.text,
let touch = touches.first,
let (range, action) = matching(touch.location(in: self)) else {
super.touchesBegan(touches, with: event)
return
}
// 设置触摸范围内容
touched = (string, range, action)
// 设置高亮样式
var temp: [NSAttributedString.Key: Any] = [:]
action.highlights.forEach { temp.merge($0.attributes, uniquingKeysWith: { $1 }) }
attributedText = string.value.reset(range: range) { (attributes) in
attributes.merge(temp, uniquingKeysWith: { $1 })
}
}
其中这里会发生崩溃:'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds'
attributedText = string.value.reset(range: range) { (attributes) in
attributes.merge(temp, uniquingKeysWith: { $1 })
}