From 8b60364d63475718a1227783f8df497888fb756d Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 7 Nov 2023 08:19:55 -0600 Subject: [PATCH] updated color range to set the length if current range is 0.0 Signed-off-by: Matt Bruce --- .../Label/Attributes/ColorLabelAttribute.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Label/Attributes/ColorLabelAttribute.swift b/VDS/Components/Label/Attributes/ColorLabelAttribute.swift index e266f15f..354fbc93 100644 --- a/VDS/Components/Label/Attributes/ColorLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ColorLabelAttribute.swift @@ -23,7 +23,7 @@ public struct ColorLabelAttribute: LabelAttributeModel { //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(location: Int, length: Int, color: UIColor = .black, isForegroundColor: Bool = true) { + public init(location: Int = 0, length: Int = 0, color: UIColor = .black, isForegroundColor: Bool = true) { self.location = location self.length = length self.color = color @@ -31,8 +31,12 @@ public struct ColorLabelAttribute: LabelAttributeModel { } public func setAttribute(on attributedString: NSMutableAttributedString) { + var colorRange = range + if length == 0 && location == 0 { + colorRange = .init(location: location, length: attributedString.length) + } let attributeKey = isForegroundColor ? NSAttributedString.Key.foregroundColor : NSAttributedString.Key.backgroundColor - attributedString.removeAttribute(attributeKey, range: range) - attributedString.addAttribute(attributeKey, value: color, range: range) + attributedString.removeAttribute(attributeKey, range: colorRange) + attributedString.addAttribute(attributeKey, value: color, range: colorRange) } }