Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-06-19 14:38:13 -05:00
parent 735e061831
commit 58388b81b8
2 changed files with 11 additions and 42 deletions

View File

@ -195,17 +195,12 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
//set lineHeight
if textStyle.lineHeight > 0.0 {
let lineHeight = textStyle.lineHeight
let adjustment = lineHeight > font.lineHeight ? 2.0 : 1.0
let baselineOffset = (lineHeight - font.lineHeight) / 2.0 / adjustment
paragraph.maximumLineHeight = lineHeight
paragraph.minimumLineHeight = lineHeight
mutableText.addAttribute(.baselineOffset, value: baselineOffset, range: entireRange)
mutableText.addAttribute( .paragraphStyle, value: paragraph, range: entireRange)
} else {
mutableText.addAttribute( .paragraphStyle, value: paragraph, range: entireRange)
}
mutableText.addAttribute( .paragraphStyle, value: paragraph, range: entireRange)
if let attributes = attributes {
//loop through the models attributes
for attribute in attributes {

View File

@ -38,15 +38,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
open var textPosition: TextPosition = .left { didSet { setNeedsUpdate() }}
open var userInfo = [String: Primitive]()
open var edgeInset: UIEdgeInsets = .zero {
didSet {
setNeedsUpdate()
}
}
override open var text: String? {
didSet {
attributes = nil
@ -178,38 +170,20 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
attributedString.addAttribute(.kern, value: textStyle.letterSpacing, range: entireRange)
}
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = textPosition.textAlignment
paragraph.lineBreakMode = lineBreakMode
//set lineHeight
if textStyle.lineHeight > 0.0 {
let lineHeight = textStyle.lineHeight
let adjustment = lineHeight > font.lineHeight ? 2.0 : 1.0
let baselineOffset = (lineHeight - font.lineHeight) / 2.0 / adjustment
let paragraph = NSMutableParagraphStyle().with {
$0.maximumLineHeight = lineHeight
$0.minimumLineHeight = lineHeight
$0.alignment = textPosition.textAlignment
$0.lineBreakMode = lineBreakMode
}
attributedString.addAttribute(.baselineOffset, value: baselineOffset, range: entireRange)
attributedString.addAttribute( .paragraphStyle, value: paragraph, range: entireRange)
} else if textPosition != .left {
let paragraph = NSMutableParagraphStyle().with {
$0.alignment = textPosition.textAlignment
$0.lineBreakMode = lineBreakMode
}
attributedString.addAttribute( .paragraphStyle, value: paragraph, range: entireRange)
paragraph.maximumLineHeight = lineHeight
paragraph.minimumLineHeight = lineHeight
}
attributedString.addAttribute( .paragraphStyle, value: paragraph, range: entireRange)
}
open override func drawText(in rect: CGRect) {
super.drawText(in: rect.inset(by: edgeInset))
}
open override var intrinsicContentSize: CGSize {
let size = super.intrinsicContentSize
return CGSize(width: size.width + edgeInset.left + edgeInset.right, height: size.height + edgeInset.top + edgeInset.bottom)
}
//--------------------------------------------------
// MARK: - Actionable
//--------------------------------------------------