From a741ac8463cd5efe33f6a27001a9518c3a207730 Mon Sep 17 00:00:00 2001 From: Alejandro Moya Date: Thu, 21 Jul 2016 14:29:03 -0300 Subject: [PATCH] added minimumLineHeight and applied ceil on height added minimumLineHeight to be able to handle emojis properly and applied ceil on intrinsicContentSize() to avoid glitches created by decimal pixels --- ActiveLabel/ActiveLabel.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ActiveLabel/ActiveLabel.swift b/ActiveLabel/ActiveLabel.swift index c0f2abbb..765b8fcd 100644 --- a/ActiveLabel/ActiveLabel.swift +++ b/ActiveLabel/ActiveLabel.swift @@ -39,7 +39,9 @@ public protocol ActiveLabelDelegate: class { @IBInspectable public var lineSpacing: Float = 0 { didSet { updateTextStorage(parseText: false) } } - + @IBInspectable public var minimumLineHeight: Float = 0 { + didSet { updateTextStorage(parseText: false) } + } // MARK: - public methods public func handleMentionTap(handler: (String) -> ()) { mentionTapHandler = handler @@ -135,7 +137,7 @@ public protocol ActiveLabelDelegate: class { let superSize = super.intrinsicContentSize() textContainer.size = CGSize(width: superSize.width, height: CGFloat.max) let size = layoutManager.usedRectForTextContainer(textContainer) - return CGSize(width: ceil(size.width), height: ceil(size.height)) + return CGSize(width: size.width, height: ceil(size.height)) } // MARK: - touch events @@ -306,7 +308,7 @@ public protocol ActiveLabelDelegate: class { paragraphStyle.lineBreakMode = NSLineBreakMode.ByWordWrapping paragraphStyle.alignment = textAlignment paragraphStyle.lineSpacing = CGFloat(lineSpacing) - + paragraphStyle.minimumLineHeight = CGFloat(minimumLineHeight > 0 ? minimumLineHeight: self.font.pointSize * 1.14) attributes[NSParagraphStyleAttributeName] = paragraphStyle mutAttrString.setAttributes(attributes, range: range)