From eb48d8a807382c7d2dd6e92a8323648e7358173b Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 11:26:14 -0600 Subject: [PATCH] include isForeground Signed-off-by: Matt Bruce --- .../Label/Attributes/ColorLabelAttribute.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Label/Attributes/ColorLabelAttribute.swift b/VDS/Components/Label/Attributes/ColorLabelAttribute.swift index 8d70296d..e266f15f 100644 --- a/VDS/Components/Label/Attributes/ColorLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ColorLabelAttribute.swift @@ -19,17 +19,20 @@ public struct ColorLabelAttribute: LabelAttributeModel { public var location: Int public var length: Int public var color: UIColor + public var isForegroundColor: Bool //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(location: Int, length: Int, color: UIColor = .black) { + public init(location: Int, length: Int, color: UIColor = .black, isForegroundColor: Bool = true) { self.location = location self.length = length self.color = color + self.isForegroundColor = isForegroundColor } public func setAttribute(on attributedString: NSMutableAttributedString) { - attributedString.removeAttribute(.foregroundColor, range: range) - attributedString.addAttribute(.foregroundColor, value: color, range: range) + let attributeKey = isForegroundColor ? NSAttributedString.Key.foregroundColor : NSAttributedString.Key.backgroundColor + attributedString.removeAttribute(attributeKey, range: range) + attributedString.addAttribute(attributeKey, value: color, range: range) } }