From 0d6b904a7f6375cc74ed854a5484aeab16b06cd8 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 19 Sep 2019 10:54:28 -0400 Subject: [PATCH 01/12] current state. --- MVMCoreUI/Atoms/Views/Label.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index ed99fcac..c9fa1b06 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -34,6 +34,10 @@ public typealias ActionBlock = () -> () return !text.isEmpty || !attributedText.string.isEmpty } + public var getRange: NSRange { + return NSRange(location: 0, length: text?.count ?? 0) + } + //------------------------------------------------------ // MARK: - Multi-Action Text //------------------------------------------------------ @@ -611,6 +615,19 @@ extension Label { appendActionableClause(range: range, actionBlock: actionBlock) } + @objc public func makeAllTextLinkable(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { + + setActionAttributes(range: getRange) + let actionBlock = createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) + appendActionableClause(range: getRange, actionBlock: actionBlock) + } + + @objc public func makeAllTextLinkable(actionBlock: @escaping ActionBlock) { + + setActionAttributes(range: getRange) + appendActionableClause(range: getRange, actionBlock: actionBlock) + } + @objc private func textLinkTapped(_ gesture: UITapGestureRecognizer) { for clause in clauses { From efbb68b4cd5c7cdb5aab4ee2a301389cbcdc19a2 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 19 Sep 2019 14:09:51 -0400 Subject: [PATCH 02/12] latest. not perfect. --- MVMCoreUI/Atoms/Views/Label.swift | 63 ++++++++++++++----- .../Atoms/Views/LabelWithInternalButton.swift | 4 +- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index c9fa1b06..aa677cd1 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -42,6 +42,7 @@ public typealias ActionBlock = () -> () // MARK: - Multi-Action Text //------------------------------------------------------ + /// Data store of the tappable ranges of the text. public var clauses: [ActionableClause] = [] { didSet { isUserInteractionEnabled = !clauses.isEmpty @@ -114,6 +115,29 @@ public typealias ActionBlock = () -> () standardFontSize = size } + /// Convenience to init Label as a TextButton. All text will behave as a link. + @objc convenience public init(text: String, actionBlock: @escaping ActionBlock) { + self.init() + self.text = text + setTextLinkState(range: getRange, actionBlock: actionBlock) + } + + /// Convenience to init Label where the provided text will be marked as tappable by the given range. + @objc convenience public init(text: String, range: NSRange, actionBlock: @escaping ActionBlock) { + self.init() + self.text = text + setTextLinkState(range: range, actionBlock: actionBlock) + } + + /// Convenience to init Label with the link comprised of range, actionMap and delegateObject + @objc convenience public init(text: String, range: NSRange, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { + self.init() + self.text = text + if let actionBlock = Label.createActionBlockFor(label: self, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) { + setTextLinkState(range: range, actionBlock: actionBlock) + } + } + //------------------------------------------------------ // MARK: - Factory Functions //------------------------------------------------------ @@ -309,8 +333,9 @@ public typealias ActionBlock = () -> () guard let actionLabel = label as? Label else { continue } actionLabel.addActionAttributes(range: range, string: attributedString) - let actionBlock = actionLabel.createActionBlockFrom(actionMap: json, additionalData: additionalData, delegateObject: delegate) - actionLabel.appendActionableClause(range: range, actionBlock: actionBlock) + if let actionBlock = Label.createActionBlockFor(label: actionLabel, actionMap: json, additionalData: additionalData, delegateObject: delegate) { + actionLabel.appendActionableClause(range: range, actionBlock: actionBlock) + } default: continue @@ -563,9 +588,10 @@ extension Label { clauses = [] } - public func createActionBlockFrom(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) -> ActionBlock { - return { [weak self] in - if let wSelf = self, (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate?.button?(wSelf, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { + public static func createActionBlockFor(label: Label?, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) -> ActionBlock? { + guard let label = label else { return nil } + return { + if (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate?.button?(label, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } @@ -595,8 +621,7 @@ extension Label { */ @objc public func addTappableLinkAttribute(range: NSRange, actionBlock: @escaping ActionBlock) { - setActionAttributes(range: range) - appendActionableClause(range: range, actionBlock: actionBlock) + setTextLinkState(range: range, actionBlock: actionBlock) } /** @@ -610,22 +635,28 @@ extension Label { */ @objc public func addTappableLinkAttribute(range: NSRange, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { - setActionAttributes(range: range) - let actionBlock = createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) - appendActionableClause(range: range, actionBlock: actionBlock) + if let actionBlock = Label.createActionBlockFor(label: self, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) { + setTextLinkState(range: range, actionBlock: actionBlock) + } } @objc public func makeAllTextLinkable(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { - - setActionAttributes(range: getRange) - let actionBlock = createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) - appendActionableClause(range: getRange, actionBlock: actionBlock) + + if let actionBlock = Label.createActionBlockFor(label: self, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) { + setTextLinkState(range: getRange, actionBlock: actionBlock) + } } @objc public func makeAllTextLinkable(actionBlock: @escaping ActionBlock) { - setActionAttributes(range: getRange) - appendActionableClause(range: getRange, actionBlock: actionBlock) + setTextLinkState(range: getRange, actionBlock: actionBlock) + } + + /// Underlines the tappable region and stores the tap logic for interation. + private func setTextLinkState(range: NSRange, actionBlock: @escaping ActionBlock) { + + setActionAttributes(range: range) + appendActionableClause(range: range, actionBlock: actionBlock) } @objc private func textLinkTapped(_ gesture: UITapGestureRecognizer) { diff --git a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift index ff2e751d..44f254f4 100644 --- a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift +++ b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift @@ -207,7 +207,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt @objc public func setActionMap(_ actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { - actionBlock = label?.createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) + actionBlock = Label.createActionBlockFor(label: label, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) } //------------------------------------------------------ @@ -377,7 +377,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt actionText = actionMap?.optionalStringForKey(KeyTitle) backText = actionMap?.optionalStringForKey(KeyTitlePostfix) text = getTextFromStringComponents() - actionBlock = label?.createActionBlockFrom(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) + actionBlock = Label.createActionBlockFor(label: label, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) setLabelAttributes() } From b3cc938a9e4504ad3a5dd9af81f7f39e2592f602 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 20 Sep 2019 16:11:46 -0400 Subject: [PATCH 03/12] Improved accuracy of link label detection. --- MVMCoreUI/Atoms/Views/Label.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index aa677cd1..e1c4cc5e 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -689,7 +689,7 @@ extension UITapGestureRecognizer { paragraph.alignment = label.textAlignment let stagedAttributedString = NSMutableAttributedString(attributedString: attributedText) - stagedAttributedString.addAttributes([NSAttributedString.Key.paragraphStyle: paragraph], range: NSRange(location: 0, length: attributedText.string.count)) + stagedAttributedString.addAttributes([NSAttributedString.Key.paragraphStyle: paragraph], range: NSRange(location: 0, length: attributedText.string.count)) let textStorage = NSTextStorage(attributedString: stagedAttributedString) let layoutManager = NSLayoutManager() @@ -704,8 +704,8 @@ extension UITapGestureRecognizer { textContainer.size = label.bounds.size let indexOfGlyph = layoutManager.glyphIndex(for: location(in: label), in: textContainer) - - return NSLocationInRange(indexOfGlyph, targetRange) + + return layoutManager.boundingRect(forGlyphRange: targetRange, in: textContainer).contains(location(in: label)) && NSLocationInRange(indexOfGlyph, targetRange) } } From 4770aa6e6bd4c78fd557e42754d766fd488f97b4 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 23 Sep 2019 12:35:51 -0400 Subject: [PATCH 04/12] Label Improvements. Conveniences added. Greater accuracy to tap detection provided. --- MVMCoreUI/Atoms/Views/Label.swift | 67 +++++++++++-------- .../Atoms/Views/LabelWithInternalButton.swift | 4 +- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index e1c4cc5e..c62bdf52 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -115,25 +115,11 @@ public typealias ActionBlock = () -> () standardFontSize = size } - /// Convenience to init Label as a TextButton. All text will behave as a link. - @objc convenience public init(text: String, actionBlock: @escaping ActionBlock) { - self.init() - self.text = text - setTextLinkState(range: getRange, actionBlock: actionBlock) - } - - /// Convenience to init Label where the provided text will be marked as tappable by the given range. - @objc convenience public init(text: String, range: NSRange, actionBlock: @escaping ActionBlock) { - self.init() - self.text = text - setTextLinkState(range: range, actionBlock: actionBlock) - } - /// Convenience to init Label with the link comprised of range, actionMap and delegateObject @objc convenience public init(text: String, range: NSRange, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { self.init() self.text = text - if let actionBlock = Label.createActionBlockFor(label: self, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) { + if let actionBlock = createActionBlockFor(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) { setTextLinkState(range: range, actionBlock: actionBlock) } } @@ -333,7 +319,7 @@ public typealias ActionBlock = () -> () guard let actionLabel = label as? Label else { continue } actionLabel.addActionAttributes(range: range, string: attributedString) - if let actionBlock = Label.createActionBlockFor(label: actionLabel, actionMap: json, additionalData: additionalData, delegateObject: delegate) { + if let actionBlock = actionLabel.createActionBlockFor(actionMap: json, additionalData: additionalData, delegateObject: delegate) { actionLabel.appendActionableClause(range: range, actionBlock: actionBlock) } @@ -510,7 +496,7 @@ public typealias ActionBlock = () -> () } /// Call to detect in the attributedText contains an NSTextAttachment. - func textContainsTextAttachment() -> Bool { + func containsTextAttachment() -> Bool { guard let attributedText = attributedText else { return false } @@ -588,10 +574,9 @@ extension Label { clauses = [] } - public static func createActionBlockFor(label: Label?, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) -> ActionBlock? { - guard let label = label else { return nil } - return { - if (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate?.button?(label, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { + public func createActionBlockFor(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) -> ActionBlock? { + return { [weak self] in + if let wSelf = self, (delegateObject as? MVMCoreUIDelegateObject)?.buttonDelegate?.button?(wSelf, shouldPerformActionWithMap: actionMap, additionalData: additionalData) ?? true { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) } } @@ -635,19 +620,19 @@ extension Label { */ @objc public func addTappableLinkAttribute(range: NSRange, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { - if let actionBlock = Label.createActionBlockFor(label: self, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) { + if let actionBlock = createActionBlockFor(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) { setTextLinkState(range: range, actionBlock: actionBlock) } } - @objc public func makeAllTextLinkable(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { + @objc public func makeTextButton(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { - if let actionBlock = Label.createActionBlockFor(label: self, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) { + if let actionBlock = createActionBlockFor(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) { setTextLinkState(range: getRange, actionBlock: actionBlock) } } - @objc public func makeAllTextLinkable(actionBlock: @escaping ActionBlock) { + @objc public func makeTextButton(actionBlock: @escaping ActionBlock) { setTextLinkState(range: getRange, actionBlock: actionBlock) } @@ -689,7 +674,7 @@ extension UITapGestureRecognizer { paragraph.alignment = label.textAlignment let stagedAttributedString = NSMutableAttributedString(attributedString: attributedText) - stagedAttributedString.addAttributes([NSAttributedString.Key.paragraphStyle: paragraph], range: NSRange(location: 0, length: attributedText.string.count)) + stagedAttributedString.addAttributes([NSAttributedString.Key.paragraphStyle: paragraph], range: NSRange(location: 0, length: attributedText.string.count)) let textStorage = NSTextStorage(attributedString: stagedAttributedString) let layoutManager = NSLayoutManager() @@ -703,9 +688,33 @@ extension UITapGestureRecognizer { textContainer.maximumNumberOfLines = label.numberOfLines textContainer.size = label.bounds.size - let indexOfGlyph = layoutManager.glyphIndex(for: location(in: label), in: textContainer) - - return layoutManager.boundingRect(forGlyphRange: targetRange, in: textContainer).contains(location(in: label)) && NSLocationInRange(indexOfGlyph, targetRange) + let tapLocation = location(in: label) + let indexOfGlyph = layoutManager.glyphIndex(for: tapLocation, in: textContainer) + let intrinsicWidth = label.intrinsicContentSize.width + + // Assert that tapped occured within acceptable bounds based on alignment. + switch label.textAlignment { + case .right: + if tapLocation.x < label.bounds.width - intrinsicWidth { + return false + } + case .center: + let halfBounds = label.bounds.width / 2 + let halfintrinsicWidth = intrinsicWidth / 2 + + if tapLocation.x > halfBounds + halfintrinsicWidth{ + return false + } else if tapLocation.x < halfBounds - halfintrinsicWidth { + return false + } + default: // Left align + if tapLocation.x > intrinsicWidth { + return false + } + } + + // Affirms that the tap occured in the desired rect of provided by the target range. + return layoutManager.boundingRect(forGlyphRange: targetRange, in: textContainer).contains(tapLocation) && NSLocationInRange(indexOfGlyph, targetRange) } } diff --git a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift index 44f254f4..070cc0f7 100644 --- a/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift +++ b/MVMCoreUI/Atoms/Views/LabelWithInternalButton.swift @@ -207,7 +207,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt @objc public func setActionMap(_ actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { - actionBlock = Label.createActionBlockFor(label: label, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) + actionBlock = label?.createActionBlockFor(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) } //------------------------------------------------------ @@ -377,7 +377,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt actionText = actionMap?.optionalStringForKey(KeyTitle) backText = actionMap?.optionalStringForKey(KeyTitlePostfix) text = getTextFromStringComponents() - actionBlock = Label.createActionBlockFor(label: label, actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) + actionBlock = label?.createActionBlockFor(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) setLabelAttributes() } From d0797a4825b99e30780da40ed86b3ed17000e141 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 23 Sep 2019 12:43:52 -0400 Subject: [PATCH 05/12] mild updates. --- MVMCoreUI/Atoms/Views/Label.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index c62bdf52..3c2d73c1 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -115,7 +115,7 @@ public typealias ActionBlock = () -> () standardFontSize = size } - /// Convenience to init Label with the link comprised of range, actionMap and delegateObject + /// Convenience to init Label with a link comprised of range, actionMap and delegateObject @objc convenience public init(text: String, range: NSRange, actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { self.init() self.text = text @@ -555,7 +555,7 @@ extension Label { } } -// MARK: - Multi-Action Functionality +// MARK: - Multi-Link Functionality extension Label { /// Applied to existing text. Removes underlines of tappable links and assoated actionable clauses. @@ -582,7 +582,7 @@ extension Label { } } - func addActionAttributes(range: NSRange, string: NSMutableAttributedString?) { + private func addActionAttributes(range: NSRange, string: NSMutableAttributedString?) { guard let string = string else { return } string.addAttributes([NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue], range: range) @@ -625,6 +625,7 @@ extension Label { } } + /// Converts the entire text into a link. All characters will be underlined and the intrinsic bounds will respond to tap. @objc public func makeTextButton(actionMap: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) { if let actionBlock = createActionBlockFor(actionMap: actionMap, additionalData: additionalData, delegateObject: delegateObject) { @@ -632,6 +633,7 @@ extension Label { } } + /// Converts the entire text into a link. All characters will be underlined and the intrinsic bounds will respond to tap. @objc public func makeTextButton(actionBlock: @escaping ActionBlock) { setTextLinkState(range: getRange, actionBlock: actionBlock) @@ -647,7 +649,6 @@ extension Label { @objc private func textLinkTapped(_ gesture: UITapGestureRecognizer) { for clause in clauses { - // This determines if we tapped on the desired range of text. if let range = clause.range, gesture.didTapAttributedTextInLabel(self, inRange: range) { clause.performAction() From 7b6f3d6b88c52c99badb25f48bfd06ef84472e3e Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 23 Sep 2019 14:23:37 -0400 Subject: [PATCH 06/12] spelling. --- MVMCoreUI/Atoms/Views/Label.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 3c2d73c1..74394a90 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -701,11 +701,11 @@ extension UITapGestureRecognizer { } case .center: let halfBounds = label.bounds.width / 2 - let halfintrinsicWidth = intrinsicWidth / 2 + let halfIntrinsicWidth = intrinsicWidth / 2 - if tapLocation.x > halfBounds + halfintrinsicWidth{ + if tapLocation.x > halfBounds + halfIntrinsicWidth { return false - } else if tapLocation.x < halfBounds - halfintrinsicWidth { + } else if tapLocation.x < halfBounds - halfIntrinsicWidth { return false } default: // Left align From 252beb311a35837f657111f8803f163cca7c7403 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 22 Oct 2019 11:40:50 -0400 Subject: [PATCH 07/12] dynamic type --- MVMCoreUI/Atoms/Views/Label.swift | 2 +- MVMCoreUI/Utility/MFFonts.m | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 6fc496bd..d3195f45 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -80,7 +80,7 @@ public typealias ActionBlock = () -> () //------------------------------------------------------ @objc public func setupView() { - + adjustsFontForContentSizeCategory = true backgroundColor = .clear numberOfLines = 0 lineBreakMode = .byWordWrapping diff --git a/MVMCoreUI/Utility/MFFonts.m b/MVMCoreUI/Utility/MFFonts.m index 65326e6c..fad79299 100644 --- a/MVMCoreUI/Utility/MFFonts.m +++ b/MVMCoreUI/Utility/MFFonts.m @@ -41,12 +41,16 @@ + (nullable UIFont *)mfFont75Bd:(CGFloat)size { [self loadMVMFonts]; - return [UIFont fontWithName:@"NHaasGroteskDSStd-75Bd" size:size]; + UIFont *font = [UIFont fontWithName:@"NHaasGroteskDSStd-75Bd" size:size]; + UIFontMetrics *metrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleHeadline]; + return [metrics scaledFontForFont:font]; } + (nullable UIFont *)mfFont55Rg:(CGFloat)size { [self loadMVMFonts]; - return [UIFont fontWithName:@"NHaasGroteskDSStd-55Rg" size:size]; + UIFont *font = [UIFont fontWithName:@"NHaasGroteskDSStd-55Rg" size:size];; + UIFontMetrics *metrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleBody]; + return [metrics scaledFontForFont:font]; } + (nullable UIFont *)mfFontOcratxt:(CGFloat)size { From 8aaa8cb77f82eb3f0b40025f5b9f315fc730af88 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 23 Oct 2019 15:17:01 -0400 Subject: [PATCH 08/12] centered. --- MVMCoreUI/Atoms/Views/Label.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index fba8545f..b0871957 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -732,7 +732,7 @@ extension UITapGestureRecognizer { return false } case .center: - let halfBounds = label.bounds.width / 2 + let halfBounds = label.center.x let halfIntrinsicWidth = intrinsicWidth / 2 if tapLocation.x > halfBounds + halfIntrinsicWidth { From a4aedaad90c1bc08d9b15aae13dd8b36804f142e Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 23 Oct 2019 15:43:57 -0400 Subject: [PATCH 09/12] revert. --- MVMCoreUI/Atoms/Views/Label.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index b0871957..fba8545f 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -732,7 +732,7 @@ extension UITapGestureRecognizer { return false } case .center: - let halfBounds = label.center.x + let halfBounds = label.bounds.width / 2 let halfIntrinsicWidth = intrinsicWidth / 2 if tapLocation.x > halfBounds + halfIntrinsicWidth { From f0c7f6bce6ddf379677c965dd67c625c602c0a07 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 24 Oct 2019 09:19:16 -0400 Subject: [PATCH 10/12] unwrap. --- MVMCoreUI/Atoms/Views/Label.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 9da9a50d..109f2f97 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -322,8 +322,9 @@ public typealias ActionBlock = () -> () guard let actionLabel = label as? Label else { continue } actionLabel.addActionAttributes(range: range, string: attributedString) - let actionBlock = actionLabel.createActionBlockFor(actionMap: attribute, additionalData: additionalData, delegateObject: delegate) - actionLabel.appendActionableClause(range: range, actionBlock: actionBlock!) + if let actionBlock = actionLabel.createActionBlockFor(actionMap: attribute, additionalData: additionalData, delegateObject: delegate) { + actionLabel.appendActionableClause(range: range, actionBlock: actionBlock) + } default: continue From 0ff661f3c4941c0b277c99eab0e5294046a257bc Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 24 Oct 2019 09:31:01 -0400 Subject: [PATCH 11/12] revert for legacy --- MVMCoreUI/Atoms/Views/ViewConstrainingView.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index c6b1023e..66a3a83d 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -314,10 +314,14 @@ [self.molecule updateView:size]; [MFStyler setMarginsForView:self size:size defaultHorizontal:self.updateViewHorizontalDefaults top:(self.updateViewVerticalDefaults ? self.topMarginPadding : 0) bottom:(self.updateViewVerticalDefaults ? self.bottomMarginPadding : 0)]; UIEdgeInsets margins = [MVMCoreUIUtility getMarginsForView:self]; - [self setLeftPinConstant:margins.left]; - [self setRightPinConstant:margins.right]; - [self setTopPinConstant:margins.top]; - [self setBottomPinConstant:margins.bottom]; + if (self.updateViewHorizontalDefaults) { + [self setLeftPinConstant:margins.left]; + [self setRightPinConstant:margins.right]; + } + if (self.updateViewVerticalDefaults) { + [self setTopPinConstant:margins.top]; + [self setBottomPinConstant:margins.bottom]; + } } #pragma mark - MVMCoreUIMoleculeViewProtocol From 603652537dd900baa040169dac39b176d6005a7c Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 24 Oct 2019 09:34:51 -0400 Subject: [PATCH 12/12] remove large text --- MVMCoreUI/Atoms/Views/Label.swift | 2 +- MVMCoreUI/Utility/MFFonts.m | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 5c825bb5..52ee43d1 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -80,7 +80,7 @@ public typealias ActionBlock = () -> () //------------------------------------------------------ @objc public func setupView() { - adjustsFontForContentSizeCategory = true + backgroundColor = .clear numberOfLines = 0 lineBreakMode = .byWordWrapping diff --git a/MVMCoreUI/Utility/MFFonts.m b/MVMCoreUI/Utility/MFFonts.m index fad79299..65326e6c 100644 --- a/MVMCoreUI/Utility/MFFonts.m +++ b/MVMCoreUI/Utility/MFFonts.m @@ -41,16 +41,12 @@ + (nullable UIFont *)mfFont75Bd:(CGFloat)size { [self loadMVMFonts]; - UIFont *font = [UIFont fontWithName:@"NHaasGroteskDSStd-75Bd" size:size]; - UIFontMetrics *metrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleHeadline]; - return [metrics scaledFontForFont:font]; + return [UIFont fontWithName:@"NHaasGroteskDSStd-75Bd" size:size]; } + (nullable UIFont *)mfFont55Rg:(CGFloat)size { [self loadMVMFonts]; - UIFont *font = [UIFont fontWithName:@"NHaasGroteskDSStd-55Rg" size:size];; - UIFontMetrics *metrics = [UIFontMetrics metricsForTextStyle:UIFontTextStyleBody]; - return [metrics scaledFontForFont:font]; + return [UIFont fontWithName:@"NHaasGroteskDSStd-55Rg" size:size]; } + (nullable UIFont *)mfFontOcratxt:(CGFloat)size {