fixed color attribute

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-04-24 16:41:38 -05:00
parent 7c8690bcb4
commit 86c675a07f

View File

@ -31,12 +31,14 @@ public struct ColorLabelAttribute: LabelAttributeModel {
} }
public func setAttribute(on attributedString: NSMutableAttributedString) { public func setAttribute(on attributedString: NSMutableAttributedString) {
guard isValidRange(on: attributedString) else { return }
var colorRange = range var colorRange = range
if length == 0 && location == 0 { if length == 0 && location == 0 {
colorRange = .init(location: location, length: attributedString.length) colorRange = .init(location: location, length: attributedString.length)
if !attributedString.isValid(range: colorRange) { return }
} else {
guard isValidRange(on: attributedString) else { return }
} }
let attributeKey = isForegroundColor ? NSAttributedString.Key.foregroundColor : NSAttributedString.Key.backgroundColor let attributeKey = isForegroundColor ? NSAttributedString.Key.foregroundColor : NSAttributedString.Key.backgroundColor
attributedString.removeAttribute(attributeKey, range: colorRange) attributedString.removeAttribute(attributeKey, range: colorRange)
attributedString.addAttribute(attributeKey, value: color, range: colorRange) attributedString.addAttribute(attributeKey, value: color, range: colorRange)