From 76fe9749ad7bb59b2d4331c6da183d37a1fc585c Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 9 Apr 2020 10:05:48 -0400 Subject: [PATCH] latest --- MVMCoreUI/BaseClasses/TextView.swift | 25 ++++++++++++++++++++--- MVMCoreUI/BaseClasses/TextViewModel.swift | 4 ++-- MVMCoreUI/Styles/MFStyler.h | 1 + MVMCoreUI/Styles/MFStyler.m | 22 ++++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/BaseClasses/TextView.swift b/MVMCoreUI/BaseClasses/TextView.swift index bc1c2133..735abfaf 100644 --- a/MVMCoreUI/BaseClasses/TextView.swift +++ b/MVMCoreUI/BaseClasses/TextView.swift @@ -18,6 +18,9 @@ import UIKit private var initialSetupPerformed = false + /// Set this property if you want updateView to update the font based on this standard and the size passed in. + public var standardFontSize: CGFloat = 0.0 + public var isShowingPlaceholder = true /// Set to true to hide the blinking textField cursor. @@ -198,18 +201,34 @@ extension TextView: MoleculeViewProtocol { textColor = model.textColor.uiColor layer.borderColor = model.borderColor?.cgColor layer.borderWidth = model.borderWidth -// font = model.fontStyle - // placeholderFont = model.placeholderFont +// placeholderFont = model.placeholderFont text = model.text isShowingPlaceholder = model.text.isEmpty placeholderTraits.text = model.placeholder - uiTextViewDelegate = delegateObject?.uiTextViewDelegate if let accessibilityText = model.accessibilityText { accessibilityLabel = accessibilityText } + if let fontStyle = model.fontStyle?.rawValue { + MFStyler.styleTextView(self, withStyle: fontStyle, genericScaling: false) + standardFontSize = font?.pointSize ?? 0 + if let font = font { + textTraits.font = font + } + } else { + let fontSize = model.fontSize + if let fontSize = fontSize { + standardFontSize = fontSize + } + if let fontName = model.fontName { + font = MFFonts.mfFont(withName: fontName, size: fontSize ?? standardFontSize) + } else if let fontSize = fontSize { + font = font?.updateSize(fontSize) + } + } + if isEditable { MVMCoreUICommonViewsUtility.addDismissToolbar(to: self, delegate: delegateObject?.uiTextViewDelegate) } diff --git a/MVMCoreUI/BaseClasses/TextViewModel.swift b/MVMCoreUI/BaseClasses/TextViewModel.swift index 6b335614..a4660b54 100644 --- a/MVMCoreUI/BaseClasses/TextViewModel.swift +++ b/MVMCoreUI/BaseClasses/TextViewModel.swift @@ -100,8 +100,8 @@ open class TextViewModel: MoleculeModelProtocol { borderColor = try typeContainer.decodeIfPresent(Color.self, forKey: .borderColor) accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .accessibilityText) - fontName = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) + fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .fontSize) + fontName = try typeContainer.decodeIfPresent(String.self, forKey: .fontName) fontStyle = try typeContainer.decodeIfPresent(LabelModel.FontStyle.self, forKey: .fontStyle) height = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .height) } diff --git a/MVMCoreUI/Styles/MFStyler.h b/MVMCoreUI/Styles/MFStyler.h index 6accea28..a1e49927 100644 --- a/MVMCoreUI/Styles/MFStyler.h +++ b/MVMCoreUI/Styles/MFStyler.h @@ -294,6 +294,7 @@ B3 -> Legal /// Will style the label based on the string. Accepted values, including mva3.0 fonts and 2.0 fonts H1, H2, H3, H32, B1, B2, B3, B20 + (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style; + (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling; ++ (void)styleTextView:(nonnull UITextView *)label withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling; + (void)styleLabelH1:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling; + (void)styleLabelH1:(nonnull UILabel *)label; diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index 213c205e..2805d4ee 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -853,6 +853,28 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } } ++ (void)styleTextView:(nonnull UITextView *)label withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling { + if ([self styleMVA3Label:label withStyle:style genericScaling:genericScaling]) { + //try mva 3.0 font first + } else if ([style isEqualToString:@"H1"]) { + [self styleLabelH1:label genericScaling:genericScaling]; + } else if ([style isEqualToString:@"H2"]) { + [self styleLabelH2:label genericScaling:genericScaling]; + } else if ([style isEqualToString:@"H3"]) { + [self styleLabelH3:label genericScaling:genericScaling]; + } else if ([style isEqualToString:@"H32"]) { + [self styleLabelH32:label genericScaling:genericScaling]; + } else if ([style isEqualToString:@"B1"]) { + [self styleLabelB1:label genericScaling:genericScaling]; + } else if ([style isEqualToString:@"B3"]) { + [self styleLabelB3:label genericScaling:genericScaling]; + } else if ([style isEqualToString:@"B20"]) { + [self styleLabelB20:label genericScaling:genericScaling]; + } else { + [self styleLabelB2:label genericScaling:genericScaling]; + } +} + + (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style { [self styleLabel:label withStyle:style genericScaling:YES]; }