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 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)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user