include isForeground

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-11-10 11:26:14 -06:00
parent cd94bfde67
commit eb48d8a807

View File

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