updated attributedString

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-07-21 10:44:06 -05:00
parent 02150f8e8c
commit 2d0252311a

View File

@ -19,20 +19,28 @@ extension NSAttributedString {
} }
extension NSMutableAttributedString { extension NSMutableAttributedString {
public static func mutableText(for text: String, textStyle: TextStyle, textColor: UIColor, alignment: NSTextAlignment = .left, lineBreakMode: NSLineBreakMode) -> NSMutableAttributedString { public static func mutableText(for text: String, textStyle: TextStyle, useScaledFont: Bool = true, textColor: UIColor, alignment: NSTextAlignment = .left, lineBreakMode: NSLineBreakMode) -> NSMutableAttributedString {
//create the paragraph for specific properties //create the paragraph for specific properties
let paragraph = NSMutableParagraphStyle() let paragraph = NSMutableParagraphStyle()
paragraph.alignment = alignment paragraph.alignment = alignment
paragraph.lineBreakMode = lineBreakMode paragraph.lineBreakMode = lineBreakMode
var defaultFont = textStyle.font
var lineHeight = textStyle.lineHeight
if useScaledFont {
lineHeight = textStyle.scaledLineHeight
defaultFont = defaultFont.scaledFont
}
//set lineHeight //set lineHeight
if textStyle.lineHeight > 0.0 { if textStyle.lineHeight > 0.0 {
paragraph.maximumLineHeight = textStyle.lineHeight paragraph.maximumLineHeight = lineHeight
} }
//create the attributeArray //create the attributeArray
var attributes: [NSAttributedString.Key : Any] = [.font: textStyle.font, var attributes: [NSAttributedString.Key : Any] = [.font: defaultFont,
.foregroundColor: textColor, .foregroundColor: textColor,
.paragraphStyle: paragraph] .paragraphStyle: paragraph]