From 6d52663b4f66bd8ee7ae6760e2ff4b84c6d371c7 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 17 Oct 2019 14:06:01 -0400 Subject: [PATCH] fixed small error in refactor. --- MVMCoreUI/Atoms/Views/Label.swift | 4 ++-- MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index fefd686d..6fc496bd 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -510,7 +510,7 @@ public typealias ActionBlock = () -> () Provides a text container and layout manager of how the text would appear on screen. They are used in tandem to derive low-level TextKit results of the label. */ - public func abstractTextContainer() -> (NSTextContainer, NSLayoutManager)? { + public func abstractTextContainer() -> (NSTextContainer, NSLayoutManager, NSTextStorage)? { // Must configure the attributed string to translate what would appear on screen to accurately analyze. guard let attributedText = attributedText else { return nil } @@ -533,7 +533,7 @@ public typealias ActionBlock = () -> () textContainer.maximumNumberOfLines = numberOfLines textContainer.size = bounds.size - return (textContainer, layoutManager) + return (textContainer, layoutManager, textStorage) } public static func boundingRect(forCharacterRange range: NSRange, in label: Label) -> CGRect { diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index 568a551c..2e8b9bfc 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -126,14 +126,12 @@ import UIKit /// NOTE: Should only be called when displayed or about to be displayed. public func alignAccessoryToHero() { + // Layout call required to force draw in memory to get dinmensions of subviews. layoutIfNeeded() guard let heroLabel = findHeroLabel(views: contentView.subviews), let hero = heroLabel.hero else { return } let rect = Label.boundingRect(forCharacterRange: NSRange(location: hero, length: 1), in: heroLabel) - let rectView = UIView(frame: rect) - heroLabel.addSubview(rectView) - accessoryView?.center.y = contentView.convert(rectView.center, from: heroLabel).y + accessoryView?.center.y = contentView.convert(UIView(frame: rect).center, from: heroLabel).y heroAccessoryCenter = accessoryView?.center - rectView.removeFromSuperview() } /// Traverses the view hierarchy for a 🦸‍♂️heroic Label.