From 58388b81b84f483545a364bdcc5fafec5a762baf Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 19 Jun 2023 14:38:13 -0500 Subject: [PATCH] updated Signed-off-by: Matt Bruce --- .../Buttons/Button/ButtonBase.swift | 9 +--- VDS/Components/Label/Label.swift | 44 ++++--------------- 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index a7f5ca17..60844f89 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -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 { diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index c460530b..111743d0 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -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 //--------------------------------------------------