insert label range validations to prevent crashes
This commit is contained in:
parent
84246df1b3
commit
19fd207470
@ -829,7 +829,14 @@ extension Label {
|
|||||||
|
|
||||||
private func addActionAttributes(range: NSRange, string: NSMutableAttributedString?) {
|
private func addActionAttributes(range: NSRange, string: NSMutableAttributedString?) {
|
||||||
|
|
||||||
guard let string = string else { return }
|
guard let string = string,
|
||||||
|
range.location > 0 && range.location < string.length
|
||||||
|
else { return }
|
||||||
|
|
||||||
|
var range = range
|
||||||
|
if range.upperBound > string.length {
|
||||||
|
range = NSRange(location: range.location, length: string.length - range.location)
|
||||||
|
}
|
||||||
|
|
||||||
string.addAttributes([NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue], range: range)
|
string.addAttributes([NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue], range: range)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user