added extension for NSMutableAttributedString
refactoctored code to use extension Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
94bdb22fbd
commit
e0540a68ce
@ -167,12 +167,9 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
|
||||
alignment: titleLabel?.textAlignment ?? .center,
|
||||
lineBreakMode: titleLabel?.lineBreakMode ?? .byTruncatingTail)
|
||||
|
||||
//apply any attributes
|
||||
if let attributes = textAttributes {
|
||||
//loop through the models attributes
|
||||
for attribute in attributes {
|
||||
//add attribute on the string
|
||||
attribute.setAttribute(on: mutableText)
|
||||
}
|
||||
mutableText.apply(attributes: attributes)
|
||||
}
|
||||
|
||||
//set the attributed text
|
||||
|
||||
@ -54,3 +54,14 @@ public extension NSAttributedString {
|
||||
return TextStyleLabelAttribute(location: range.location, length: range.length, textStyle: style)
|
||||
}
|
||||
}
|
||||
|
||||
extension NSMutableAttributedString {
|
||||
public func apply(attribute: any LabelAttributeModel) {
|
||||
attribute.setAttribute(on: self)
|
||||
}
|
||||
|
||||
public func apply(attributes: [any LabelAttributeModel]) {
|
||||
attributes.forEach { apply(attribute: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -273,12 +273,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
|
||||
actions = []
|
||||
|
||||
if let attributes = attributes {
|
||||
//loop through the models attributes
|
||||
for attribute in attributes {
|
||||
|
||||
//add attribute on the string
|
||||
attribute.setAttribute(on: mutableAttributedString)
|
||||
}
|
||||
mutableAttributedString.apply(attributes: attributes)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user