updated for textcolor

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-01-26 15:16:56 -06:00
parent 2394055815
commit 9aad50fb0b

View File

@ -27,14 +27,14 @@ public struct TextStyleLabelAttribute: LabelAttributeModel {
public var location: Int public var location: Int
public var length: Int public var length: Int
public var textStyle: TextStyle public var textStyle: TextStyle
public var textColor: UIColor public var textColor: UIColor?
public var textPosition: TextPosition public var textPosition: TextPosition
public var lineBreakMode: NSLineBreakMode public var lineBreakMode: NSLineBreakMode
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
//-------------------------------------------------- //--------------------------------------------------
public init(location: Int, length: Int, textStyle: TextStyle, textColor: UIColor = .black, textPosition: TextPosition = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping) { public init(location: Int, length: Int, textStyle: TextStyle, textColor: UIColor? = nil, textPosition: TextPosition = .left, lineBreakMode: NSLineBreakMode = .byWordWrapping) {
self.location = location self.location = location
self.length = length self.length = length
self.textStyle = textStyle self.textStyle = textStyle
@ -45,9 +45,11 @@ public struct TextStyleLabelAttribute: LabelAttributeModel {
public func setAttribute(on attributedString: NSMutableAttributedString) { public func setAttribute(on attributedString: NSMutableAttributedString) {
attributedString.removeAttribute(.font, range: range) attributedString.removeAttribute(.font, range: range)
attributedString.removeAttribute(.foregroundColor, range: range)
attributedString.addAttribute(.font, value: textStyle.font, range: range) attributedString.addAttribute(.font, value: textStyle.font, range: range)
attributedString.addAttribute(.foregroundColor, value: textColor, range: range) if let textColor {
attributedString.removeAttribute(.foregroundColor, range: range)
attributedString.addAttribute(.foregroundColor, value: textColor, range: range)
}
setStyleAttributes(attributedString) setStyleAttributes(attributedString)
} }