fixed bug in TextStyle Attribute dealing with lineHeight and baseline
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
183630f6b5
commit
c68faaec31
@ -63,18 +63,15 @@ 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
|
||||||
$0.alignment = textPosition.value
|
$0.alignment = textPosition.value
|
||||||
$0.lineBreakMode = lineBreakMode
|
$0.lineBreakMode = lineBreakMode
|
||||||
}
|
}
|
||||||
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 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user