From acc91902e56b8ad05926d7924278a18dc3ab39ff Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Fri, 10 Jun 2022 16:20:37 -0400 Subject: [PATCH 1/4] Global font changes --- .../Atomic/Atoms/Views/Label/Label.swift | 11 +- .../Molecules/HeadersAndFooters/Header.swift | 4 +- .../MoleculeHeaderView.swift | 4 +- .../HeadlineBody.swift | 24 +- MVMCoreUI/BaseClasses/TableViewCell.swift | 4 +- MVMCoreUI/Styles/MFStyler.h | 13 - MVMCoreUI/Styles/MFStyler.m | 318 +++--------------- MVMCoreUI/Styles/Styler.swift | 218 ++++++------ 8 files changed, 179 insertions(+), 417 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index fcbb31e4..c524b7b3 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -295,8 +295,8 @@ public typealias ActionBlock = () -> () accessibilityLabel = accessibilityText } - if let fontStyle = labelModel.fontStyle?.rawValue { - MFStyler.styleLabel(self, withStyle: fontStyle, genericScaling: false) + if let fontStyle = labelModel.fontStyle { + fontStyle.styleLabel(self, genericScaling: false) standardFontSize = font.pointSize } else { let fontSize = labelModel.fontSize @@ -428,7 +428,7 @@ public typealias ActionBlock = () -> () label.accessibilityLabel = json?.optionalStringForKey("accessibilityText") if let fontStyle = json?.optionalStringForKey("fontStyle") { - MFStyler.styleLabel(label, withStyle: fontStyle, genericScaling: mvmLabel == nil) + MFStyler.style(label: label, styleString: fontStyle, genericScaling: mvmLabel == nil) mvmLabel?.standardFontSize = label.font.pointSize } else { let fontSize = json?["fontSize"] as? CGFloat @@ -490,7 +490,7 @@ public typealias ActionBlock = () -> () case "font": if let fontStyle = attribute.optionalStringForKey("style") { - let styles = MFStyler.styleGetAttributedString("0", withStyle: fontStyle, genericScaling: mvmLabel == nil) + let styles = MFStyler.getAttributedString(for: "0", styleString: fontStyle, genericScaling: mvmLabel == nil) attributedString.removeAttribute(.font, range: range) attributedString.removeAttribute(.foregroundColor, range: range) attributedString.addAttributes(styles.attributes(at: 0, effectiveRange: nil), range: range) @@ -531,8 +531,7 @@ public typealias ActionBlock = () -> () //------------------------------------------------------ public func setFontStyle(_ fontStyle: Styler.Font, _ scale: Bool = true) { - font = fontStyle.getFont(false) - textColor = .mvmBlack + fontStyle.styleLabel(self, genericScaling: false) setScale(scale) } diff --git a/MVMCoreUI/Atomic/Molecules/HeadersAndFooters/Header.swift b/MVMCoreUI/Atomic/Molecules/HeadersAndFooters/Header.swift index 73b42dea..9d061f76 100644 --- a/MVMCoreUI/Atomic/Molecules/HeadersAndFooters/Header.swift +++ b/MVMCoreUI/Atomic/Molecules/HeadersAndFooters/Header.swift @@ -33,7 +33,7 @@ open class HeaderView: Container { public override func setupView() { super.setupView() - line.setStyle(.heavy) + line.setStyle(.none) addSubview(line) NSLayoutConstraint.pinViewBottom(toSuperview: line, useMargins: false, constant: 0).isActive = true NSLayoutConstraint.pinViewLeft(toSuperview: line, useMargins: true, constant: 0).isActive = true @@ -43,7 +43,7 @@ open class HeaderView: Container { // MARK: - MoleculeViewProtocol open override func reset() { super.reset() - line.setStyle(.heavy) + line.setStyle(.none) molecule?.reset() } diff --git a/MVMCoreUI/Atomic/Molecules/HeadersAndFooters/MoleculeHeaderView.swift b/MVMCoreUI/Atomic/Molecules/HeadersAndFooters/MoleculeHeaderView.swift index 9e4afed6..4e999997 100644 --- a/MVMCoreUI/Atomic/Molecules/HeadersAndFooters/MoleculeHeaderView.swift +++ b/MVMCoreUI/Atomic/Molecules/HeadersAndFooters/MoleculeHeaderView.swift @@ -31,7 +31,7 @@ public class MoleculeHeaderView: MoleculeContainer { public override func setupView() { super.setupView() - line.setStyle(.heavy) + line.setStyle(.none) addSubview(line) NSLayoutConstraint.pinViewBottom(toSuperview: line, useMargins: false, constant: 0).isActive = true NSLayoutConstraint.pinViewLeft(toSuperview: line, useMargins: true, constant: 0).isActive = true @@ -40,7 +40,7 @@ public class MoleculeHeaderView: MoleculeContainer { open override func reset() { super.reset() - line.setStyle(.heavy) + line.setStyle(.none) } open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { diff --git a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift index 43c22dcc..ae0d22c4 100644 --- a/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift +++ b/MVMCoreUI/Atomic/Molecules/VerticalCombinationViews/HeadlineBody.swift @@ -54,27 +54,27 @@ open class HeadlineBody: View { } public func styleLandingPageHeader() { - headlineLabel.setFontStyle(.Title2XLarge) - messageLabel.setFontStyle(.RegularBodySmall) - spaceBetweenLabelsConstant = Padding.Two + headlineLabel.setFontStyle(.RegularTitle2XLarge) + messageLabel.setFontStyle(.RegularTitleMedium) + spaceBetweenLabelsConstant = Padding.Four } public func stylePageHeader() { - headlineLabel.setFontStyle(.BoldTitleLarge) + headlineLabel.setFontStyle(.RegularTitleLarge) + messageLabel.setFontStyle(.RegularBodyLarge) + spaceBetweenLabelsConstant = Padding.Two + } + + public func styleListItem() { + headlineLabel.setFontStyle(.RegularTitleSmall) messageLabel.setFontStyle(.RegularBodySmall) spaceBetweenLabelsConstant = Padding.One } - public func styleListItem() { - headlineLabel.setFontStyle(.BoldBodySmall) - messageLabel.setFontStyle(.RegularBodySmall) - spaceBetweenLabelsConstant = 0 - } - public func styleListItemDivider() { - headlineLabel.setFontStyle(.BoldTitleMedium) + headlineLabel.setFontStyle(.BoldTitleSmall) messageLabel.setFontStyle(.RegularBodySmall) - spaceBetweenLabelsConstant = 0 + spaceBetweenLabelsConstant = Padding.Two } //-------------------------------------------------- diff --git a/MVMCoreUI/BaseClasses/TableViewCell.swift b/MVMCoreUI/BaseClasses/TableViewCell.swift index a80969ba..053bedd0 100644 --- a/MVMCoreUI/BaseClasses/TableViewCell.swift +++ b/MVMCoreUI/BaseClasses/TableViewCell.swift @@ -45,10 +45,10 @@ import UIKit bottomSeparatorView?.setStyle(.secondary) case .shortDivider?: topSeparatorView?.setStyle(.none) - bottomSeparatorView?.setStyle(.primary) + bottomSeparatorView?.setStyle(.none) case .tallDivider?: topSeparatorView?.setStyle(.none) - bottomSeparatorView?.setStyle(.primary) + bottomSeparatorView?.setStyle(.none) case .sectionFooter?: topSeparatorView?.setStyle(.none) bottomSeparatorView?.setStyle(.none) diff --git a/MVMCoreUI/Styles/MFStyler.h b/MVMCoreUI/Styles/MFStyler.h index d8676016..541ede8c 100644 --- a/MVMCoreUI/Styles/MFStyler.h +++ b/MVMCoreUI/Styles/MFStyler.h @@ -217,7 +217,6 @@ B3 -> Legal + (nullable UIFont *)fontForHeadlineSmall:(BOOL)genericScaling; + (nullable UIFont *)fontForHeadlineSmall2; + (nullable UIFont *)fontForHeadlineSmall2:(BOOL)genericScaling; -+ (nullable UIFont *)fontForHeadlineSmall2ForWidth:(CGFloat)size; + (nullable UIFont *)fontB1ForWidth:(CGFloat)size; + (nullable UIFont *)fontForBodyWithSize:(CGFloat)size genericScaling:(BOOL)genericScaling; + (nullable UIFont *)fontB2ForWidth:(CGFloat)size; @@ -287,15 +286,8 @@ B3 -> Legal + (void)styleLabelRegularMicro:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling; + (void)styleLabelRegularMicro:(nonnull UILabel *)label; -/// Will style the label with mva 3.0 fonts based on the string. -+ (BOOL)styleMVA3Label:(nonnull UILabel *)label withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling; - #pragma mark - 2.0 styles -/// 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)styleLabelH1:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling; + (void)styleLabelH1:(nonnull UILabel *)label; @@ -377,11 +369,6 @@ B3 -> Legal + (nonnull NSAttributedString *)styleGetRegularMicroAttributedString:(nullable NSString *)string; + (nonnull NSAttributedString *)styleGetRegularMicroAttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling; - -/// Will style the string based on the string. Accepted values, H1, H2, H3, H32, B1, B2, B3, B20 -+ (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string withStyle:(nullable NSString *)style; -+ (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling; - + (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string font:(nonnull UIFont *)font color:(nonnull UIColor *)color; + (nonnull NSAttributedString *)styleGetH1AttributedString:(nullable NSString *)string; + (nonnull NSAttributedString *)styleGetH2AttributedString:(nullable NSString *)string; diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index 48ca21a8..9f5a02c0 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -113,27 +113,11 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; #pragma mark - 3.0 fonts + (nonnull UIFont *)getMVA3FontSize:(CGFloat)size bold:(BOOL)isBold { - if (isBold) { - if (size >= 15) { - return [MFFonts mfFontDSBold:size]; - } else { - return [MFFonts mfFontTXBold:size]; - } - } else { - if (size >= 15) { - return [MFFonts mfFontDSRegular:size]; - } else { - return [MFFonts mfFontTXRegular:size]; - } - } + return [self getFontForSize:size isBold:isBold]; } + (nonnull UIFont *)fontTitle2XLarge:(BOOL)genericScaling { - CGFloat size = 36; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:YES]; + return [self getFontForStyleString:@"Title2XLarge" genericScaling:genericScaling]; } + (nonnull UIFont *)fontTitle2XLarge { @@ -141,22 +125,15 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull UIFont *)fontTitleXLarge:(BOOL)genericScaling { - CGFloat size = 32; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:YES]; + return [self getFontForStyleString:@"TitleXLarge" genericScaling:genericScaling]; } -+ (nonnull UIFont *)fontTitleXLarge{ + ++ (nonnull UIFont *)fontTitleXLarge { return [self fontTitleXLarge:YES]; } + (nonnull UIFont *)fontBoldTitleLarge:(BOOL)genericScaling { - CGFloat size = 24; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:YES]; + return [self getFontForStyleString:@"BoldTitleLarge" genericScaling:genericScaling]; } + (nonnull UIFont *)fontBoldTitleLarge { @@ -164,11 +141,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull UIFont *)fontRegularTitleLarge:(BOOL)genericScaling { - CGFloat size = 24; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:NO]; + return [self getFontForStyleString:@"RegularTitleLarge" genericScaling:genericScaling]; } + (nonnull UIFont *)fontRegularTitleLarge { @@ -176,11 +149,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull UIFont *)fontBoldTitleMedium:(BOOL)genericScaling { - CGFloat size = 20; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:YES]; + return [self getFontForStyleString:@"BoldTitleMedium" genericScaling:genericScaling]; } + (nonnull UIFont *)fontBoldTitleMedium { @@ -188,11 +157,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull UIFont *)fontRegularTitleMedium:(BOOL)genericScaling { - CGFloat size = 20; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:NO]; + return [self getFontForStyleString:@"RegularTitleMedium" genericScaling:genericScaling]; } + (nonnull UIFont *)fontRegularTitleMedium { @@ -200,11 +165,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull UIFont *)fontBoldBodyLarge:(BOOL)genericScaling { - CGFloat size = 16; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:YES]; + return [self getFontForStyleString:@"BoldBodyLarge" genericScaling:genericScaling]; } + (nonnull UIFont *)fontBoldBodyLarge { @@ -212,11 +173,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull UIFont *)fontRegularBodyLarge:(BOOL)genericScaling { - CGFloat size = 16; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:NO]; + return [self getFontForStyleString:@"RegularBodyLarge" genericScaling:genericScaling]; } + (nonnull UIFont *)fontRegularBodyLarge { @@ -224,11 +181,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull UIFont *)fontBoldBodySmall:(BOOL)genericScaling { - CGFloat size = 13; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:YES]; + return [self getFontForStyleString:@"BoldBodySmall" genericScaling:genericScaling]; } + (nonnull UIFont *)fontBoldBodySmall { @@ -236,11 +189,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull UIFont *)fontRegularBodySmall:(BOOL)genericScaling { - CGFloat size = 13; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:NO]; + return [self getFontForStyleString:@"RegularBodySmall" genericScaling:genericScaling]; } + (nonnull UIFont *)fontRegularBodySmall { @@ -248,11 +197,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull UIFont *)fontBoldMicro:(BOOL)genericScaling { - CGFloat size = 11; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:YES]; + return [self getFontForStyleString:@"BoldMicro" genericScaling:genericScaling]; } + (nonnull UIFont *)fontBoldMicro { @@ -260,11 +205,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull UIFont *)fontRegularMicro:(BOOL)genericScaling { - CGFloat size = 11; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [self getMVA3FontSize:size bold:NO]; + return [self getFontForStyleString:@"RegularMicro" genericScaling:genericScaling]; } + (nonnull UIFont *)fontRegularMicro { @@ -275,11 +216,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; #pragma mark - 2.0 fonts + (nullable UIFont *)fontH1:(BOOL)genericScaling { - CGFloat size = 40; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont75Bd:size]; + return [self getFontForStyleString:@"H1" genericScaling:genericScaling]; } + (nullable UIFont *)fontH1 { @@ -287,11 +224,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontH2:(BOOL)genericScaling { - CGFloat size = 25; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont75Bd:size]; + return [self getFontForStyleString:@"H2" genericScaling:genericScaling]; } + (nullable UIFont *)fontH2 { @@ -299,11 +232,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontH3:(BOOL)genericScaling { - CGFloat size = 18; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont75Bd:size]; + return [self getFontForStyleString:@"H3" genericScaling:genericScaling]; } + (nullable UIFont *)fontH3 { @@ -311,11 +240,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontH32:(BOOL)genericScaling { - CGFloat size = 32; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont75Bd:size]; + return [self getFontForStyleString:@"H32" genericScaling:genericScaling]; } + (nullable UIFont *)fontH32 { @@ -323,11 +248,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontB1:(BOOL)genericScaling { - CGFloat size = 13; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont75Bd:size]; + return [self getFontForStyleString:@"B1" genericScaling:genericScaling]; } + (nullable UIFont *)fontB1 { @@ -335,11 +256,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontB2:(BOOL)genericScaling { - CGFloat size = 13; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont55Rg:size]; + return [self getFontForStyleString:@"B2" genericScaling:genericScaling]; } + (nullable UIFont *)fontB2 { @@ -347,11 +264,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontB3:(BOOL)genericScaling { - CGFloat size = 11; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont55Rg:size]; + return [self getFontForStyleString:@"B3" genericScaling:genericScaling]; } + (nullable UIFont *)fontB3 { @@ -359,11 +272,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontB20:(BOOL)genericScaling { - CGFloat size = 20; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont55Rg:size]; + return [self getFontForStyleString:@"B20" genericScaling:genericScaling]; } + (nullable UIFont *)fontB20 { @@ -385,11 +294,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontForBiggerHeadLine:(BOOL)genericScaling { - CGFloat size = 48; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont75Bd:size]; + return [self getFontForStyleString:@"BoldFeatureSmall" genericScaling:genericScaling]; } + (nullable UIFont *)fontForBiggerHeadline { @@ -397,31 +302,15 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontForHeadlineSmall:(BOOL)genericScaling { - CGFloat size = 15; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont75Bd:size]; + return [self getFontForStyleString:@"BoldTitleSmall" genericScaling:genericScaling]; } + (nullable UIFont *)fontForHeadlineSmall2:(BOOL)genericScaling { - CGFloat size = 16; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont75Bd:size]; -} - -+ (nullable UIFont *)fontForHeadlineSmall2ForWidth:(CGFloat)size { - CGFloat pointSize = 16; - pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size]; - return [MFFonts mfFont75Bd:pointSize]; + return [self getFontForStyleString:@"BoldTitleSmall" genericScaling:genericScaling]; } + (nullable UIFont *)fontB1ForWidth:(CGFloat)size { - CGFloat pointSize = 13; - pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size]; - return [MFFonts mfFont75Bd:pointSize]; + return [self getFontForStyleString:@"B1" scaleValue:size]; } + (nullable UIFont *)fontForBodyWithSize:(CGFloat)size genericScaling:(BOOL)genericScaling { @@ -432,9 +321,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontB2ForWidth:(CGFloat)size { - CGFloat pointSize = 13; - pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size]; - return [MFFonts mfFont55Rg:pointSize]; + return [self getFontForStyleString:@"B2" scaleValue:size]; } + (nullable UIFont *)fontForBodyWithSize:(CGFloat)size forWidth:(CGFloat)width { @@ -443,19 +330,11 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontforChatText:(BOOL)genericScaling { - CGFloat size = 14; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont55Rg:size]; + return [self getFontForStyleString:@"RegularBodyMedium" genericScaling:genericScaling]; } + (nullable UIFont *)fontForAccountLandingGreeting:(BOOL)genericScaling { - CGFloat size = 16; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont55Rg:size]; + return [self getFontForStyleString:@"RegularBodyLarge" genericScaling:genericScaling]; } + (nullable UIFont *)fontForProgressBarBottomLabel:(BOOL)genericScaling { @@ -467,47 +346,27 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontForPrimaryButton:(BOOL)genericScaling { - CGFloat size = 13; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFontTXBold:size]; + return [self getFontForStyleString:@"BoldBodyLarge" genericScaling:genericScaling]; } + (nullable UIFont *)fontForPrimaryButtonForWidth:(CGFloat)size { - CGFloat pointSize = 13; - pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size]; - return [MFFonts mfFontTXBold:pointSize]; + return [self getFontForStyleString:@"BoldBodyLarge" scaleValue:size]; } + (nullable UIFont *)fontForSmallButton:(BOOL)genericScaling { - CGFloat size = 11; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFontTXBold:size]; + return [self getFontForStyleString:@"BoldBodySmall" genericScaling:genericScaling]; } + (nullable UIFont *)fontForSmallButtonForWidth:(CGFloat)size { - CGFloat pointSize = 11; - pointSize = [[MFStyler sizeObjectGenericForCurrentDevice:pointSize] getValueBasedOnSize:size]; - return [MFFonts mfFontTXBold:pointSize]; + return [self getFontForStyleString:@"BoldBodySmall" scaleValue:size]; } + (nullable UIFont *)fontForTextField:(BOOL)genericScaling { - CGFloat size = 16; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont55Rg:size]; + return [self getFontForStyleString:@"RegularBodyLarge" genericScaling:genericScaling]; } + (nullable UIFont *)fontForTextFieldUnderLabel:(BOOL)genericScaling { - CGFloat size = 12; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont55Rg:size]; + return [self getFontForStyleString:@"RegularBodySmall" genericScaling:genericScaling]; } + (nullable UIFont *)fontForUnreadMessageOnSupport:(BOOL)genericScaling { @@ -519,11 +378,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)font5GMessage:(BOOL)genericScaling { - CGFloat size = 16; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont55Rg:size]; + return [self getFontForStyleString:@"RegularBodyLarge" genericScaling:genericScaling]; } + (nullable UIFont *)font5GMessage { @@ -554,11 +409,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontForFeedCardTitle:(BOOL)genericScaling { - CGFloat size = 16; - if (genericScaling) { - size = [self sizeFontGenericForCurrentDevice:size]; - } - return [MFFonts mfFont75Bd:size]; + return [self getFontForStyleString:@"BoldTitleSmall" genericScaling:genericScaling]; } + (nullable UIFont *)fontForLargeLoyaltyHeaderTitle:(BOOL)genericScaling { @@ -785,77 +636,8 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; [self styleLabelRegularMicro:label genericScaling:YES]; } -+ (BOOL)styleMVA3Label:(nonnull UILabel *)label withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling { - if ([style isEqualToString:@"Title2XLarge"]) { - [self styleLabelTitle2XLarge:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"TitleXLarge"]) { - [self styleLabelTitleXLarge:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"BoldTitleLarge"]) { - [self styleLabelBoldTitleLarge:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"RegularTitleLarge"]) { - [self styleLabelRegularTitleLarge:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"BoldTitleMedium"]) { - [self styleLabelBoldTitleMedium:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"RegularTitleMedium"]) { - [self styleLabelRegularTitleMedium:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"BoldBodyLarge"]) { - [self styleLabelBoldBodyLarge:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"RegularBodyLarge"]) { - [self styleLabelRegularBodyLarge:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"BoldBodySmall"]) { - [self styleLabelBoldBodySmall:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"RegularBodySmall"]) { - [self styleLabelRegularBodySmall:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"BoldMicro"]) { - [self styleLabelBoldMicro:label genericScaling:genericScaling]; - return YES; - } else if ([style isEqualToString:@"RegularMicro"]) { - [self styleLabelRegularMicro:label genericScaling:genericScaling]; - return YES; - } else { - return NO; - } -} - - #pragma mark - 2.0 Styles -+ (void)styleLabel:(nonnull UILabel *)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]; -} - + (void)styleLabelH1:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling { label.font = [MFStyler fontH1:genericScaling]; label.textColor = [UIColor blackColor]; @@ -975,30 +757,6 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; #pragma mark - Attributed Strings -+ (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string withStyle:(nullable NSString *)style { - return [self styleGetAttributedString:string withStyle:style genericScaling:YES]; -} - -+ (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling { - if ([style isEqualToString:@"H1"]) { - return [self styleGetH1AttributedString:string genericScaling:genericScaling]; - } else if ([style isEqualToString:@"H2"]) { - return [self styleGetH2AttributedString:string genericScaling:genericScaling]; - } else if ([style isEqualToString:@"H3"]) { - return [self styleGetH3AttributedString:string genericScaling:genericScaling]; - } else if ([style isEqualToString:@"H32"]) { - return [self styleGetH32AttributedString:string genericScaling:genericScaling]; - } else if ([style isEqualToString:@"B1"]) { - return [self styleGetB1AttributedString:string genericScaling:genericScaling]; - } else if ([style isEqualToString:@"B3"]) { - return [self styleGetB3AttributedString:string genericScaling:genericScaling]; - } else if ([style isEqualToString:@"B20"]) { - return [self styleGetB20AttributedString:string genericScaling:genericScaling]; - } else { - return [self styleGetB2AttributedString:string genericScaling:genericScaling]; - } -} - + (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string font:(nonnull UIFont *)font color:(nonnull UIColor *)color { NSAttributedString *attributedString = nil; if (![string isEqual:[NSNull null]] && string.length > 0) { diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 9cc487e8..e9893a94 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -7,69 +7,103 @@ // import Foundation +import UIKit open class Styler { // MARK:- Font Enum public enum Font: String, Codable { - case Title2XLarge - case TitleXLarge - case BoldTitleLarge + case RegularFeatureXLarge + case BoldFeatureXLarge + case RegularFeatureLarge + case BoldFeatureLarge + case RegularFeatureMedium + case BoldFeatureMedium + case RegularFeatureSmall + case BoldFeatureSmall + case RegularFeatureXSmall + case BoldFeatureXSmall + + case RegularTitle2XLarge + case BoldTitle2XLarge + case RegularTitleXLarge + case BoldTitleXLarge case RegularTitleLarge - case BoldTitleMedium + case BoldTitleLarge case RegularTitleMedium - case BoldBodyLarge + case BoldTitleMedium + case RegularTitleSmall + case BoldTitleSmall + case RegularBodyLarge - case BoldBodySmall + case BoldBodyLarge + case RegularBodyMedium + case BoldBodyMedium case RegularBodySmall - case BoldMicro + case BoldBodySmall case RegularMicro + case BoldMicro // Legacy Fonts - case H1 - case H32 - case H2 - case B20 - case H3 - case B1 - case B2 - case B3 + case Title2XLarge // Maps to RegularTitle2XLarge + case TitleXLarge // Maps to RegularTitleXLarge + case H1 // Maps to RegularTitle2XLarge + case H32 // Maps to RegularTitleXLarge + case H2 // Maps to RegularTitleLarge + case B20 // Maps to RegularBodyLarge + case H3 // Maps to BoldTitleMedium + case B1 // Maps to BoldBodySmall + case B2 // Maps to RegularBodySmall + case B3 // Maps to RegularMicro /// Returns the font size of the current enum case. public func pointSize() -> CGFloat { switch self { - case .H1: + case .RegularFeatureXLarge, + .BoldFeatureXLarge: + return 96 + case .RegularFeatureLarge, + .BoldFeatureLarge: + return 80 + case .RegularFeatureMedium, + .BoldFeatureMedium: + return 64 + case .RegularFeatureSmall, + .BoldFeatureSmall: + return 48 + case .RegularFeatureXSmall, + .BoldFeatureXSmall, + .RegularTitle2XLarge, + .BoldTitle2XLarge, + .Title2XLarge, + .H1: return 40 - - case .Title2XLarge: - return 36 - - case .TitleXLarge, .H32: + case .RegularTitleXLarge, + .BoldTitleXLarge, + .TitleXLarge, + .H32: return 32 - - case .H2: - return 25 - case .BoldTitleLarge, - .RegularTitleLarge: + .RegularTitleLarge, + .H2: return 24 - case .BoldTitleMedium, - .RegularTitleMedium, .B20: + .RegularTitleMedium, + .H3: return 20 - - case .H3: - return 18 - - case .BoldBodyLarge, - .RegularBodyLarge: + case .RegularTitleSmall, + .BoldTitleSmall, + .BoldBodyLarge, + .RegularBodyLarge, + .B20: return 16 - + case .RegularBodyMedium, + .BoldBodyMedium: + return 14 case .BoldBodySmall, .B1, .RegularBodySmall, .B2: - return 13 - + return 12 case .BoldMicro, .RegularMicro, .B3: return 11 @@ -90,85 +124,38 @@ open class Styler { public func isBold() -> Bool { switch self { - case .RegularTitleLarge, - .RegularTitleMedium, .B20, - .RegularBodyLarge, - .RegularBodySmall, .B2, - .RegularMicro, .B3: - return false - - case .H1, - .Title2XLarge, - .TitleXLarge, .H32, - .H2, - .BoldTitleLarge, - .BoldTitleMedium, - .H3, - .BoldBodyLarge, - .BoldBodySmall, .B1, - .BoldMicro: - return true - } - } - - /// Determines if the current enum is a legacy or modern font. - public func isLegacyFont() -> Bool { - - switch self { - case .Title2XLarge, - .TitleXLarge, - .RegularTitleLarge, - .RegularTitleMedium, - .RegularBodyLarge, - .RegularBodySmall, - .RegularMicro, + case .BoldFeatureXLarge, + .BoldFeatureLarge, + .BoldFeatureMedium, + .BoldFeatureSmall, + .BoldFeatureXSmall, + .BoldTitle2XLarge, + .BoldTitleXLarge, .BoldTitleLarge, .BoldTitleMedium, + .BoldTitleSmall, .BoldBodyLarge, + .BoldBodyMedium, .BoldBodySmall, - .BoldMicro: - return false - - case .H1, - .H32, - .H2, .H3, .B1, - .B2, - .B3, - .B20: + .BoldMicro: return true + default: + return false } } - + /// Returns the font based on the declared enum case. public func getFont(_ genericScaling: Bool = true) -> UIFont { - let size = genericScaling ? sizeFontGeneric(forCurrentDevice: pointSize()) : pointSize() - - if isLegacyFont() { - switch self { - case .B2, .B3, .B20: - return MFFonts.mfFont55Rg(size) - - default: - return MFFonts.mfFont75Bd(size) - } - } else { - if isBold() { - return size >= 13 ? MFFonts.mfFontDSBold(size) : MFFonts.mfFontTXBold(size) - - } else { - return size >= 13 ? MFFonts.mfFontDSRegular(size) : MFFonts.mfFontTXRegular(size) - } - } + return MFStyler.getFontFor(size: size, isBold: isBold()) } /// Styles the provided label to the declared enum Font case. - public func styleLabel(_ label: UILabel, textColor: UIColor = .mvmBlack, genericScaling: Bool = true) { - + public func styleLabel(_ label: UILabel, genericScaling: Bool = true) { label.font = getFont(genericScaling) - label.textColor = textColor + label.textColor = color() } } @@ -267,3 +254,34 @@ open class Styler { } } } + +@objc public extension MFStyler { + @objc static func getFontFor(size: CGFloat, isBold: Bool) -> UIFont { + if isBold { + return size >= 13 ? MFFonts.mfFontDSBold(size) : MFFonts.mfFontTXBold(size) + } else { + return size >= 13 ? MFFonts.mfFontDSRegular(size) : MFFonts.mfFontTXRegular(size) + } + } + + @objc static func getFontFor(styleString: String, genericScaling: Bool = true) -> UIFont? { + return Styler.Font(rawValue: styleString)?.getFont(genericScaling) + } + + @objc static func getFontFor(styleString: String, scaleValue: CGFloat) -> UIFont? { + guard let font = Styler.Font(rawValue: styleString), + let size = Styler.Font(rawValue: styleString)?.pointSize(), + let newSize = Styler.sizeObjectGeneric(forCurrentDevice: size)?.getValueBased(onSize: scaleValue) else { return nil } + return getFontFor(size: newSize, isBold: font.isBold()) + } + + /// Styles the label accordingly to Styler.Font + @objc static func style(label: UILabel, styleString: String, genericScaling: Bool = true) { + Styler.Font(rawValue: styleString)?.styleLabel(label, genericScaling: genericScaling) + } + + @objc static func getAttributedString(for string: String, styleString: String, genericScaling: Bool = true) -> NSAttributedString { + let font = Styler.Font(rawValue: styleString)! + return styleGetAttributedString(string, font: font.getFont(genericScaling), color: font.color()) + } +} From 123ac6b2a192fd0acf65dddda37c34a4d1a52375 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Mon, 20 Jun 2022 11:43:50 -0400 Subject: [PATCH 2/4] Feed card revert. --- MVMCoreUI/Styles/MFStyler.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index 9f5a02c0..da7077ad 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -409,7 +409,7 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontForFeedCardTitle:(BOOL)genericScaling { - return [self getFontForStyleString:@"BoldTitleSmall" genericScaling:genericScaling]; + return [self getFontForStyleString:@"BoldTitleXLarge" genericScaling:genericScaling]; } + (nullable UIFont *)fontForLargeLoyaltyHeaderTitle:(BOOL)genericScaling { From c2c6fdd524c8939315035bc38005c8df7d87302f Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Mon, 20 Jun 2022 12:55:42 -0400 Subject: [PATCH 3/4] Revert --- MVMCoreUI/Styles/MFStyler.m | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index da7077ad..e65fddc5 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -294,7 +294,11 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontForBiggerHeadLine:(BOOL)genericScaling { - return [self getFontForStyleString:@"BoldFeatureSmall" genericScaling:genericScaling]; + CGFloat size = 48; + if (genericScaling) { + size = [self sizeFontGenericForCurrentDevice:size]; + } + return [MFFonts mfFont75Bd:size]; } + (nullable UIFont *)fontForBiggerHeadline { @@ -302,11 +306,19 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontForHeadlineSmall:(BOOL)genericScaling { - return [self getFontForStyleString:@"BoldTitleSmall" genericScaling:genericScaling]; + CGFloat size = 15; + if (genericScaling) { + size = [self sizeFontGenericForCurrentDevice:size]; + } + return [MFFonts mfFont75Bd:size]; } + (nullable UIFont *)fontForHeadlineSmall2:(BOOL)genericScaling { - return [self getFontForStyleString:@"BoldTitleSmall" genericScaling:genericScaling]; + CGFloat size = 16; + if (genericScaling) { + size = [self sizeFontGenericForCurrentDevice:size]; + } + return [MFFonts mfFont75Bd:size]; } + (nullable UIFont *)fontB1ForWidth:(CGFloat)size { @@ -330,11 +342,19 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)fontforChatText:(BOOL)genericScaling { - return [self getFontForStyleString:@"RegularBodyMedium" genericScaling:genericScaling]; + CGFloat size = 14; + if (genericScaling) { + size = [self sizeFontGenericForCurrentDevice:size]; + } + return [MFFonts mfFont55Rg:size]; } + (nullable UIFont *)fontForAccountLandingGreeting:(BOOL)genericScaling { - return [self getFontForStyleString:@"RegularBodyLarge" genericScaling:genericScaling]; + CGFloat size = 16; + if (genericScaling) { + size = [self sizeFontGenericForCurrentDevice:size]; + } + return [MFFonts mfFont55Rg:size]; } + (nullable UIFont *)fontForProgressBarBottomLabel:(BOOL)genericScaling { @@ -378,7 +398,11 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nullable UIFont *)font5GMessage:(BOOL)genericScaling { - return [self getFontForStyleString:@"RegularBodyLarge" genericScaling:genericScaling]; + CGFloat size = 16; + if (genericScaling) { + size = [self sizeFontGenericForCurrentDevice:size]; + } + return [MFFonts mfFont55Rg:size]; } + (nullable UIFont *)font5GMessage { From c284614c29dcd2bc87cdf9fe08df06384c184502 Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Mon, 20 Jun 2022 12:55:55 -0400 Subject: [PATCH 4/4] Comments --- MVMCoreUI/Styles/Styler.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index e9893a94..2cbc9a00 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -256,6 +256,7 @@ open class Styler { } @objc public extension MFStyler { + /// Creates the appropriate VZW font for a given size and weight. @objc static func getFontFor(size: CGFloat, isBold: Bool) -> UIFont { if isBold { return size >= 13 ? MFFonts.mfFontDSBold(size) : MFFonts.mfFontTXBold(size) @@ -264,10 +265,12 @@ open class Styler { } } + /// Creates the appropriate VZW font for a VDS style. @objc static func getFontFor(styleString: String, genericScaling: Bool = true) -> UIFont? { return Styler.Font(rawValue: styleString)?.getFont(genericScaling) } + /// Creates the appropriate VZW font for a VDS style, scaling based on the scaleValue threshold passed in. @objc static func getFontFor(styleString: String, scaleValue: CGFloat) -> UIFont? { guard let font = Styler.Font(rawValue: styleString), let size = Styler.Font(rawValue: styleString)?.pointSize(), @@ -280,6 +283,7 @@ open class Styler { Styler.Font(rawValue: styleString)?.styleLabel(label, genericScaling: genericScaling) } + /// Returns an attributed string with the passed in VDS Style. @objc static func getAttributedString(for string: String, styleString: String, genericScaling: Bool = true) -> NSAttributedString { let font = Styler.Font(rawValue: styleString)! return styleGetAttributedString(string, font: font.getFont(genericScaling), color: font.color())