updated color range to set the length if current range is 0.0
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
e0540a68ce
commit
8b60364d63
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user