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) } }