fixed bug in TextStyle Attribute dealing with lineHeight and baseline

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-10-03 15:09:16 -05:00
parent 183630f6b5
commit c68faaec31

View File

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