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,
|
alignment: titleLabel?.textAlignment ?? .center,
|
||||||
lineBreakMode: titleLabel?.lineBreakMode ?? .byTruncatingTail)
|
lineBreakMode: titleLabel?.lineBreakMode ?? .byTruncatingTail)
|
||||||
|
|
||||||
|
//apply any attributes
|
||||||
if let attributes = textAttributes {
|
if let attributes = textAttributes {
|
||||||
//loop through the models attributes
|
mutableText.apply(attributes: attributes)
|
||||||
for attribute in attributes {
|
|
||||||
//add attribute on the string
|
|
||||||
attribute.setAttribute(on: mutableText)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//set the attributed text
|
//set the attributed text
|
||||||
|
|||||||
@ -54,3 +54,14 @@ public extension NSAttributedString {
|
|||||||
return TextStyleLabelAttribute(location: range.location, length: range.length, textStyle: style)
|
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 = []
|
actions = []
|
||||||
|
|
||||||
if let attributes = attributes {
|
if let attributes = attributes {
|
||||||
//loop through the models attributes
|
mutableAttributedString.apply(attributes: attributes)
|
||||||
for attribute in attributes {
|
|
||||||
|
|
||||||
//add attribute on the string
|
|
||||||
attribute.setAttribute(on: mutableAttributedString)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user