refactored to use AnyLabelAttribute

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-11-10 11:26:38 -06:00
parent eb48d8a807
commit f9c8e328cf

View File

@ -38,16 +38,7 @@ public extension NSAttributedString {
}
static func createAttributeModelFor(key: NSAttributedString.Key, range: NSRange, value: Any) -> (any LabelAttributeModel)? {
switch key {
case NSAttributedString.Key.font:
let value = value as! UIFont
let style = TypographicalStyle.style(for: value.fontName, size: value.pointSize)
return FontLabelAttribute(location: range.location, length: range.length, style: style)
case NSAttributedString.Key.foregroundColor:
return ColorLabelAttribute(location: range.location, length: range.length, color: value as! UIColor)
default:
return nil
}
guard let value = value as? AnyHashable else { return nil }
return AnyAttribute(location: range.location, length: range.length, key: key, value: value)
}
}