include isForeground
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
cd94bfde67
commit
eb48d8a807
@ -19,17 +19,20 @@ public struct ColorLabelAttribute: LabelAttributeModel {
|
|||||||
public var location: Int
|
public var location: Int
|
||||||
public var length: Int
|
public var length: Int
|
||||||
public var color: UIColor
|
public var color: UIColor
|
||||||
|
public var isForegroundColor: Bool
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializer
|
// 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.location = location
|
||||||
self.length = length
|
self.length = length
|
||||||
self.color = color
|
self.color = color
|
||||||
|
self.isForegroundColor = isForegroundColor
|
||||||
}
|
}
|
||||||
|
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
attributedString.removeAttribute(.foregroundColor, range: range)
|
let attributeKey = isForegroundColor ? NSAttributedString.Key.foregroundColor : NSAttributedString.Key.backgroundColor
|
||||||
attributedString.addAttribute(.foregroundColor, value: color, range: range)
|
attributedString.removeAttribute(attributeKey, range: range)
|
||||||
|
attributedString.addAttribute(attributeKey, value: color, range: range)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user