Merge branch 'bugfix/TextStyleLabelAttribute' into 'develop'

fixed bug in TextStyle Attribute dealing with lineHeight and baseline

See merge request BPHV_MIPS/vds_ios!306
This commit is contained in:
Bruce, Matt R 2024-10-03 21:04:11 +00:00
commit 2febe4595c

View File

@ -63,18 +63,15 @@ public struct TextStyleLabelAttribute: LabelAttributeModel {
//set lineHeight
if textStyle.lineHeight > 0.0 {
let lineHeight = textStyle.lineHeight
let adjustment = lineHeight > textStyle.font.lineHeight ? 2.0 : 1.0
let baselineOffset = (lineHeight - textStyle.font.lineHeight) / 2.0 / adjustment
let lineHeight = textStyle.lineHeight + abs(textStyle.edgeInsets.bottom) + abs(textStyle.edgeInsets.top)
let paragraph = NSMutableParagraphStyle().with {
$0.maximumLineHeight = lineHeight
$0.maximumLineHeight = lineHeight
$0.minimumLineHeight = lineHeight
$0.alignment = textPosition.value
$0.lineBreakMode = lineBreakMode
}
attributedString.removeAttribute(.baselineOffset, range: range)
attributedString.removeAttribute(.paragraphStyle, range: range)
attributedString.addAttribute(.baselineOffset, value: baselineOffset, range: range)
attributedString.addAttribute(.paragraphStyle, value: paragraph, range: range)
} else if textPosition != .left {
@ -87,3 +84,4 @@ public struct TextStyleLabelAttribute: LabelAttributeModel {
}
}
}