From 29465f82815c76c51d5704e538e80cecd7d7517a Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 1 Apr 2020 14:18:51 -0400 Subject: [PATCH 01/31] refresh styler --- MVMCoreUI.xcodeproj/project.pbxproj | 4 + MVMCoreUI/Styles/Styler.swift | 1207 +++++++++++++++++++++++++++ 2 files changed, 1211 insertions(+) create mode 100644 MVMCoreUI/Styles/Styler.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 7ae72de5..3f13e17b 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -87,6 +87,7 @@ 0A41BA6E2344FCD400D4C0BC /* CATransaction+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */; }; 0A41BA7F23453A6400D4C0BC /* TextEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A41BA7E23453A6400D4C0BC /* TextEntryField.swift */; }; 0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */; }; + 0A6682AA2435125F00AD3CA1 /* Styler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682A92435125F00AD3CA1 /* Styler.swift */; }; 0A69F611241BDEA700F7231B /* RuleAnyRequiredModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */; }; 0A6BF4722360C56C0028F841 /* BaseDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */; }; 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; }; @@ -472,6 +473,7 @@ 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CATransaction+Extension.swift"; sourceTree = ""; }; 0A41BA7E23453A6400D4C0BC /* TextEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextEntryField.swift; sourceTree = ""; }; 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleGuidelinesProtocol.swift; sourceTree = ""; }; + 0A6682A92435125F00AD3CA1 /* Styler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Styler.swift; sourceTree = ""; }; 0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleAnyRequiredModel.swift; sourceTree = ""; }; 0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseDropdownEntryField.swift; sourceTree = ""; }; 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyButton.swift; sourceTree = ""; }; @@ -1466,6 +1468,7 @@ children = ( D29DF13821E68636003B2FB9 /* MFStyler.h */, D29DF13921E68637003B2FB9 /* MFStyler.m */, + 0A6682A92435125F00AD3CA1 /* Styler.swift */, ); path = Styles; sourceTree = ""; @@ -2210,6 +2213,7 @@ 011D95AD2406BB57000E3791 /* FormHolderProtocol.swift in Sources */, 01509D932327ECFB00EF99AA /* ProgressBar.swift in Sources */, D260106523D0CEA700764D80 /* StackModel.swift in Sources */, + 0A6682AA2435125F00AD3CA1 /* Styler.swift in Sources */, D29770F521F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift new file mode 100644 index 00000000..f5b90149 --- /dev/null +++ b/MVMCoreUI/Styles/Styler.swift @@ -0,0 +1,1207 @@ +// +// Styler.swift +// MVMCoreUI +// +// Created by Kevin Christiano on 4/1/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation +import MVMCore + +public protocol VogueProtocol { + +} + +public protocol VogueViewProtocol { + +} + +public protocol VogueTextProtocol: VogueProtocol { + func styleFont(_ font: UIFont) + func styleTextColor(_ textColor: UIColor) +} + + +struct Padding { + + static let One: CGFloat = 6 + static let Two: CGFloat = 12 + static let Three: CGFloat = 18 + static let Four: CGFloat = 24 + static let Five: CGFloat = 30 + static let Six: CGFloat = 36 + static let Seven: CGFloat = 42 + static let Eight: CGFloat = 48 + static let Nine: CGFloat = 54 + static let Ten: CGFloat = 60 + + static let TableCellParagraphSpace: CGFloat = 3 + static let FooterLabelParagraphSpace: CGFloat = 4 + static let WebViewInset: CGFloat = 8 + static let HeightTableSeperatorHeight: CGFloat = 1 + static let MFHeightForSwitch: CGFloat = 22 + static let MFWidthForSwitch: CGFloat = 42 + static let DisableOppacity: CGFloat = 0.5 + static let PaymentMethodViewHeightWidthMultiplier: CGFloat = 0.55 + static let MinCellHeight: CGFloat = 96 + static let HeightIphone5: CGFloat = 568 + static let DefaultOptionCellHeight: CGFloat = 120 + static let PromoViewHeight: CGFloat = 41.9 + static let BetweenFields: CGFloat = 24 + static let LabelWithInternalButtonLineSpace: CGFloat = 2 + static let PrimaryButtonTop: CGFloat = 36 + + struct Default { + static let Standard: CGFloat = 24 + static let HorizontalSpacing: CGFloat = 32 + static let VerticalSpacing: CGFloat = 32 + static let VerticalSpacing3: CGFloat = 24 + } + + struct Horizontal { + static let HeadlineWhiteView: CGFloat = 60 + static let Large: CGFloat = 72 + static let BetweenRelatedItems: CGFloat = 16 + } + + struct Vertical { + static let WhiteGrayView: CGFloat = 72 + static let HeadlineAlternate: CGFloat = 48 + } +} + + +public class Styler { + + enum MFViewBorder: Int { + case top + case left + case bottom + case right + } + + enum MFTimeFormatUnit: Int { + case mfTimeFormatColon = 0 //!{days} : {hour} : {minutes} : {seconds} + case mfTimeFormatNormal = 1 // will end with days hours minutes seconds, when left days less than 2, it will change to 'day' + } + + //-------------------------------------------------- + // MARK: - Enum + //-------------------------------------------------- + + public enum Style: String { + case H1 + case H2 + case H3 + case H32 + case B1 + case B2 + case B3 + case B20 + + func font(_ genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 0 + + switch self { + case .H1: + size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 40 + return MFFonts.mfFont75Bd(size) + + case .H2: + size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 25 + return MFFonts.mfFont75Bd(size) + + case .H3: + size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 18 + return MFFonts.mfFont75Bd(size) + + case .H32: + size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 32 + return MFFonts.mfFont75Bd(size) + + case .B1: + size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 13 + return MFFonts.mfFont75Bd(size) + + case .B2: + size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 13 + return MFFonts.mfFont55Rg(size) + + case .B3: + size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 11 + return MFFonts.mfFont55Rg(size) + + case .B20: + size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 20 + return MFFonts.mfFont55Rg(size) + } + } + } + + public enum Tier { + case primary + case secondary + case ternary + case quaternary + } + + //-------------------------------------------------- + // MARK: - Functions + //-------------------------------------------------- + + class func splitTextFieldWidth() -> CGFloat { + return splitTextFieldWidth(forViewWidth: MVMCoreUISplitViewController.getDetailViewWidth()) + } + + class func splitTextFieldWidth(forViewWidth width: CGFloat) -> CGFloat { + return (width - CGFloat(PaddingOne)) / 2 - defaultHorizontalPaddingForApplicationWidth() + } + + class func sizeObjectGeneric(forCurrentDevice size: CGFloat) -> MFSizeObject? { + + let sizeObject = MFSizeObject(standardSize: size, standardiPadPortraitSize: size * 1.3) + sizeObject?.addLargerThanCustomSize(size * 1.4, forThreshold: MFSizeStandardiPadLandscapeThreshold) + sizeObject?.addLargerThanCustomSize(size * 1.5, forThreshold: MFSizeiPadProLandscapeThreshold) + return sizeObject + } + + class func sizeFontGeneric(forCurrentDevice size: CGFloat) -> CGFloat { + return sizeObjectGeneric(forCurrentDevice: size)?.getValueBasedOnApplicationWidth() ?? 0 + } + + //-------------------------------------------------- + // MARK: - Spacing + //-------------------------------------------------- + + class func defaultHorizontalPaddingForApplicationWidth() -> CGFloat { + return MFSizeObject(scalingStandardSize: PaddingDefaultHorizontalSpacing)?.getValueBasedOnApplicationWidth() ?? 0 + } + + class func defaultVerticalPaddingForApplicationWidth() -> CGFloat { + return MFSizeObject(scalingStandardSize: PaddingDefaultVerticalSpacing)?.getValueBasedOnApplicationWidth() ?? 0 + } + + class func defaultHorizontalPadding(forSize size: CGFloat) -> CGFloat { + return MFSizeObject(scalingStandardSize: PaddingDefaultHorizontalSpacing)?.getValueBased(onSize: size) ?? 0 + } + + class func defaultVerticalPadding(forSize size: CGFloat) -> CGFloat { + return MFSizeObject(scalingStandardSize: PaddingDefaultVerticalSpacing)?.getValueBased(onSize: size) ?? 0 + } + + class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat) { + setDefaultMarginsFor(view, size: size, horizontal: true, vertical: false) + } + + class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat, horizontal: Bool, vertical: Bool) { + + let horizontalPadding: CGFloat = horizontal ? defaultHorizontalPadding(forSize: size) : 0 + let verticalPadding: CGFloat = vertical ? PaddingDefaultVerticalSpacing3 : 0 + + DispatchQueue.main.async { + MVMCoreUIUtility.setMarginsFor(view, leading: horizontalPadding, top: verticalPadding, trailing: horizontalPadding, bottom: verticalPadding) + } + } + + class func setMarginsFor(_ view: UIView?, size: CGFloat, defaultHorizontal horizontal: Bool, top: CGFloat, bottom: CGFloat) { + + let horizontalPadding: CGFloat = horizontal ? defaultHorizontalPadding(forSize: size) : 0 + + DispatchQueue.main.async { + MVMCoreUIUtility.setMarginsFor(view, leading: horizontalPadding, top: top, trailing: horizontalPadding, bottom: bottom) + } + } + + //-------------------------------------------------- + // MARK: - Fonts + //-------------------------------------------------- + + class func fontH1(_ genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 40 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func fontH2(_ genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 25 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func fontH3(_ genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 18 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func fontH32(_ genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 32 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func fontB1(_ genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 13 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func fontB2(_ genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 13 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func fontB3(_ genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 11 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func fontB20(_ genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 20 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + //-------------------------------------------------- + // MARK: - Styles + //-------------------------------------------------- + + class func styleLabel(_ label: VogueTextProtocol, withStyle style: Style, genericScaling: Bool) { + + switch style { + case .H1: + styleLabelH1(label, genericScaling: genericScaling) + + case .H2: + styleLabelH2(label, genericScaling: genericScaling) + + case .H3: + styleLabelH3(label, genericScaling: genericScaling) + + case .H32: + styleLabelH32(label, genericScaling: genericScaling) + + case .B1: + styleLabelB1(label, genericScaling: genericScaling) + + case .B2: + styleLabelB2(label, genericScaling: genericScaling) + + case .B3: + styleLabelB3(label, genericScaling: genericScaling) + + case .B20: + styleLabelB20(label, genericScaling: genericScaling) + } + } + + class func styleLabel(_ label: UILabel, withStyle style: Style) { + styleLabel(label, withStyle: style, genericScaling: true) + } + + class func styleLabelH1(_ label: VogueTextProtocol, genericScaling: Bool = true) { + + label.styleTextColor(.black) + + if let h1 = fontH1(genericScaling) { + label.styleFont(h1) + } + } + + class func styleLabelH2(_ label: VogueTextProtocol, genericScaling: Bool = true) { + + label.styleTextColor(.black) + + if let h2 = fontH2(genericScaling) { + label.styleFont(h2) + } + } + + class func styleLabelH3(_ label: VogueTextProtocol, genericScaling: Bool = true) { + + label.styleTextColor(.black) + + if let h3 = fontH3(genericScaling) { + label.styleFont(h3) + } + } + + class func styleLabelH32(_ label: VogueTextProtocol, genericScaling: Bool = true) { + + label.styleTextColor(.black) + + if let h32 = fontH32(genericScaling) { + label.styleFont(h32) + } + } + + class func styleLabelB1(_ label: VogueTextProtocol, genericScaling: Bool = true) { + + label.styleTextColor(.black) + + if let b1 = fontB1(genericScaling) { + label.styleFont(b1) + } + } + + class func styleLabelB2(_ label: VogueTextProtocol, genericScaling: Bool = true) { + + label.styleTextColor(.black) + + if let b2 = fontB2(genericScaling) { + label.styleFont(b2) + } + } + + class func styleLabelB2(_ label: UILabel, size: CGFloat, genericScaling: Bool = true) { + label.font = fontForBody(withSize: size, genericScaling: genericScaling) + } + + class func styleLabelB3(_ label: VogueTextProtocol, genericScaling: Bool = true) { + + label.styleTextColor(.mfBackgroundGray()) + + if let b3 = fontB3(genericScaling) { + label.styleFont(b3) + } + } + + class func styleLabelB20(_ label: VogueTextProtocol, genericScaling: Bool = true) { + + label.styleTextColor(.black) + + if let b20 = fontB20(genericScaling) { + label.styleFont(b20) + } + } + + class func styleLabelTextStyle2(_ label: VogueTextProtocol, genericScaling: Bool = true) { + + label.styleTextColor(.mfBattleshipGrey()) + + if let b2 = fontB2(genericScaling) { + label.styleFont(b2) + } + } + + class func fontForBody(withSize size: CGFloat, genericScaling: Bool) -> UIFont? { + + var size = size + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func fontForBody(withSize size: CGFloat, forWidth width: CGFloat) -> UIFont? { + + let size = sizeObjectGeneric(forCurrentDevice: size)?.getValueBased(onSize: width) ?? size + + return MFFonts.mfFont55Rg(size) + } + + //-------------------------------------------------- + // MARK: - 1.0 Fonts + //-------------------------------------------------- + + class func font(forPlan genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 100 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func font(forBiggerHeadLine genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 48 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func font(forHeadlineSmall genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 15 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func font(forHeadlineSmall2 genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 16 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func fontForHeadlineSmall2(forWidth size: CGFloat) -> UIFont? { + + var pointSize: CGFloat = 16 + pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) + + return MFFonts.mfFont75Bd(pointSize) + } + + class func fontB1(forWidth size: CGFloat) -> UIFont? { + + var pointSize: CGFloat = 13 + pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) + + return MFFonts.mfFont75Bd(pointSize) + } + + //-------------------------------------------------- + // MARK: - 1.0 Styles + //-------------------------------------------------- + + class func styleFeedCardTitleLabel(_ label: UILabel) { + + label.font = Styler.fontForFeedCardTitle() + label.textColor = .black + } + + class func styleFeedCardTagLabel(_ label: UILabel) { + + label.font = Styler.fontB3() + label.textColor = .mfBrownishGrey() + } + + class func styleStandardSeparatorView(_ view: UIView) { + + view.backgroundColor = .mfBackgroundGray() + } + + class func styleLabelHeadlineSmall(_ label: UILabel, genericScaling: Bool) { + + label.font = Styler.font(forHeadlineSmall: genericScaling) + label.textColor = .black + } + + class func styleFeedCardTitleLabel(_ label: UILabel, genericScaling: Bool) { + + label.font = Styler.font(forFeedCardTitle: genericScaling) + label.textColor = UIColor.black + } + + class func styleFeedCardTagLabel(_ label: UILabel, genericScaling: Bool) { + + label.font = Styler.fontB3(genericScaling) + label.textColor = UIColor.mfBrownishGrey() + } + + class func fontB2(forWidth size: CGFloat) -> UIFont? { + + var pointSize: CGFloat = 13 + + pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) + + return MFFonts.mfFont55Rg(pointSize) + } + + class func fontforChatText(_ genericScaling: Bool = false) -> UIFont? { + + var size: CGFloat = 14 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func font(forAccountLandingGreeting genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 16 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func font(forProgressBarBottomLabel genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 10 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func font(forFeedCardTitle genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 16 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func font(forPrimaryButton genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 14 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func fontForPrimaryButton(forWidth size: CGFloat) -> UIFont? { + + var pointSize: CGFloat = 14 + pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) + return MFFonts.mfFont75Bd(pointSize) + } + + class func font(forSmallButton genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 11 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func fontForSmallButton(forWidth size: CGFloat) -> UIFont? { + + var pointSize: CGFloat = 11 + pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) + + return MFFonts.mfFont75Bd(pointSize) + } + + class func font(forTextField genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 16 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func font(forTextFieldUnderLabel genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 12 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func fontForUnreadMessage(onSupport genericScaling: Bool = false) -> UIFont? { + + var size: CGFloat = 10 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func font5GMessage(_ genericScaling: Bool) -> UIFont? { + + var size: CGFloat = 16 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func font5GMessage() -> UIFont? { + return font5GMessage(true) + } + + class func font(forHeadlineAlternative genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 24 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func fontForHeadlineAlternative(forWidth size: CGFloat) -> UIFont? { + + var pointSize: CGFloat = 24 + pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) + + return MFFonts.mfFont55Rg(pointSize) + } + + class func fontH255(_ genericScaling: Bool) -> UIFont? { + + var size: CGFloat = 25 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func font(forLargeLoyaltyHeaderTitle genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 60 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func font(forLoyaltyTitleSmall genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 42 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func font(forLoyaltyMessage genericScaling: Bool = true) -> UIFont? { + + var size: CGFloat = 20 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont55Rg(size) + } + + class func font(forPtPCard genericScaling: Bool) -> UIFont? { + + var size: CGFloat = 22 + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func fontForLabelWithTopLeftCircle(withSize size: CGFloat, genericScaling: Bool) -> UIFont? { + + var size = size + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFont75Bd(size) + } + + class func fontOcratxtWitSize(_ size: CGFloat, genericScaling: Bool) -> UIFont? { + + var size = size + + if genericScaling { + size = sizeFontGeneric(forCurrentDevice: size) + } + + return MFFonts.mfFontOcratxt(size) + } + + class func boldFont(forScaledSize size: CGFloat) -> UIFont { + return MFFonts.mfFont75Bd(sizeFontGeneric(forCurrentDevice: size))! + } + + class func regularFont(forScaledSize size: CGFloat) -> UIFont { + return MFFonts.mfFont55Rg(sizeFontGeneric(forCurrentDevice: size))! + } + + //-------------------------------------------------- + // MARK: - 1.0 Attributed Strings Style + //-------------------------------------------------- + + class func styleGetAttributedString(_ string: String?, withStyle style: String?) -> NSAttributedString { + return styleGetAttributedString(string, withStyle: Styler.Style(rawValue: style!)!, genericScaling: true) + } + + class func styleGetAttributedString(_ string: String?, withStyle style: Style, genericScaling: Bool) -> NSAttributedString { + + switch style { + case .H1: + return styleGetH1AttributedString(string, genericScaling: genericScaling) + + case .H2: + return styleGetH2AttributedString(string, genericScaling: genericScaling) + + case .H3: + return styleGetH3AttributedString(string, genericScaling: genericScaling) + + case .H32: + return styleGetH32AttributedString(string, genericScaling: genericScaling) + + case .B1: + return styleGetB1AttributedString(string, genericScaling: genericScaling) + + case .B2: + return styleGetB2AttributedString(string, genericScaling: genericScaling) + + case .B3: + return styleGetB3AttributedString(string, genericScaling: genericScaling) + + case .B20: + return styleGetB20AttributedString(string, genericScaling: genericScaling) + } + } + + class func styleGetAttributedString(_ string: String?, font: UIFont, color: UIColor) -> NSAttributedString { + + var attributedString: NSAttributedString? = nil + + if let string = string, !string.isEmpty { + attributedString = NSAttributedString(string: string, attributes: [NSAttributedString.Key.font: font, + NSAttributedString.Key.foregroundColor: color]) + } else { + attributedString = NSAttributedString(string: "") + } + + return attributedString! + } + + class func styleGetH1AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { + return styleGetAttributedString(string, font: fontH1(genericScaling)!, color: .black) + } + + class func styleGetH2AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { + return styleGetAttributedString(string, font: fontH2(genericScaling)!, color: .black) + } + + class func styleGetH3AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { + return styleGetAttributedString(string, font: fontH3(genericScaling)!, color: .black) + } + + class func styleGetH32AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { + return styleGetAttributedString(string, font: fontH32(genericScaling)!, color: .black) + } + + class func styleGetB1AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { + return styleGetAttributedString(string, font: fontB1(genericScaling)!, color: .black) + } + + class func styleGetB2AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { + return styleGetAttributedString(string, font: fontB2(genericScaling)!, color: .black) + } + + class func styleGetB3AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { + return styleGetAttributedString(string, font: fontB3(genericScaling)!, color: .mfBattleshipGrey()) + } + + class func styleGetB20AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { + return styleGetAttributedString(string, font: fontB20(genericScaling)!, color: .black) + } + + class func styleGetTopAlignedAttributeString(withLeftStringRightTop left: String?, center: String, rightString right: String?, withCenterStringFontSize fontSize: CGFloat, andColor color: UIColor) -> NSAttributedString { + + var left = left ?? "" + var center = center + var right = right ?? "" + + let text = "\(left)\(center)\(right)" + let attribs = [NSAttributedString.Key.foregroundColor: color] + var attributedText = NSMutableAttributedString(string: text, attributes: attribs) + + let centerRange = (text as NSString).range(of: center) + let centerFont = MFFonts.mfFont75Bd(fontSize) + let centerHeight = centerFont?.capHeight ?? 0.0 + attributedText.addAttributes([NSAttributedString.Key.font: MFFonts.mfFont75Bd(fontSize) as Any], range: centerRange) + + let leftRange = (text as NSString).range(of: left) + let leftFont = MFFonts.mfFont75Bd(fontSize * 0.34) + let leftHeight = leftFont?.capHeight ?? 0.0 + + if let leftFont = leftFont { + attributedText.addAttributes([NSAttributedString.Key.font: leftFont, + NSAttributedString.Key.baselineOffset: NSNumber(value: Float(centerHeight - leftHeight))], range: leftRange) + } + + let rightRange = NSRange(location: centerRange.location + centerRange.length, length: right.count ) + let rightFont = MFFonts.mfFont75Bd(fontSize * 0.34) + + let offset = Float((centerFont?.pointSize ?? 0.0) - (centerFont?.capHeight ?? 0.0) + (rightFont?.pointSize ?? 0.0) / 2) + + if let rightFont = rightFont { + attributedText.addAttributes([NSAttributedString.Key.font: rightFont, + NSAttributedString.Key.baselineOffset: offset], + range: rightRange) + } + + return attributedText + } + + class func styleGetAlignCenteredAttrituedString(_ string: inout NSMutableAttributedString?) { + + if let string = string, string.length > 0 { + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.alignment = .center + string.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: string.length)) + } + } + + class func styleGetBoldString(with inputFont: UIFont?, from inputString: String?) -> NSAttributedString? { + + let openingRange = (inputString as NSString?)?.range(of: "{") + let closingRange = (inputString as NSString?)?.range(of: "}") + let attrString = NSMutableAttributedString(string: inputString ?? "") + + if openingRange?.location != NSNotFound && closingRange?.location != NSNotFound { + let boldLength = (closingRange?.location ?? 0) - (openingRange?.location ?? 0) + if let inputFont = inputFont { + attrString.setAttributes([NSAttributedString.Key.font: inputFont], range: NSRange(location: openingRange?.location ?? 0, length: boldLength)) + } + + if let closingRange = closingRange { + attrString.replaceCharacters(in: closingRange, with: "") + } + + if let openingRange = openingRange { + attrString.replaceCharacters(in: openingRange, with: "") + } + } + + return attrString + } + + //-------------------------------------------------- + // MARK: - Gradient Colors + //-------------------------------------------------- + + class func gradientSpecialTicketGold() -> [AnyHashable] { + return [UIColor(red: 0.72, green: 0.6, blue: 0.33, alpha: 1), + UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1), + UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1), + UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1), + UIColor(red: 0.6, green: 0.42, blue: 0.07, alpha: 1)] + } + + class func gradientSpecialTicketGoldCGColor() -> [AnyHashable] { + return [UIColor(red: 0.72, green: 0.6, blue: 0.33, alpha: 1).cgColor, + UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1).cgColor, + UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1).cgColor, + UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1).cgColor, + UIColor(red: 0.6, green: 0.42, blue: 0.07, alpha: 1).cgColor].compactMap { $0 } + } + + class func styleGetLowCaseSpace(_ inputString: String?) -> String? { + + if (inputString?.count ?? 0) > 0 { + let trimmedString = inputString?.lowercased().trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) + return trimmedString + } + + return "" + } + + class func labelStrokeAttributes(_ color: UIColor?) -> [AnyHashable : Any]? { + + guard let color = color else { return nil } + + return [NSAttributedString.Key.strokeColor: color, + NSAttributedString.Key.strokeWidth: -1.0] + } + + class func mfStyleBlackPageControl(_ pageControl: UIPageControl?) { + + pageControl?.pageIndicatorTintColor = .mfLighterGray() + pageControl?.currentPageIndicatorTintColor = .black + } + + //-------------------------------------------------- + // MARK: - Custom Styling Views + //-------------------------------------------------- + + class func styleView(_ view: UIView, show border: MFViewBorder, with color: UIColor?, borderLineWidth: CGFloat, borderLineLength borderLineLengh: CGFloat) { + + let borderLine = UIView(frame: .zero) + borderLine.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(borderLine) + + switch border { + case .top: + NSLayoutConstraint.constraintPinSubview(borderLine, pinTop: true, pinBottom: false, pinLeft: false, pinRight: false) + NSLayoutConstraint.constraintPinView(borderLine, heightConstraint: true, heightConstant: borderLineWidth, widthConstraint: true, widthConstant: borderLineLengh) + NSLayoutConstraint.constraintPinSubview(borderLine, pinCenterX: true, pinCenterY: false) + + case .left: + NSLayoutConstraint.constraintPinSubview(borderLine, pinTop: false, pinBottom: false, pinLeft: true, pinRight: false) + NSLayoutConstraint.constraintPinView(borderLine, heightConstraint: true, heightConstant: borderLineLengh, widthConstraint: true, widthConstant: borderLineWidth) + NSLayoutConstraint.constraintPinSubview(borderLine, pinCenterX: false, pinCenterY: true) + + case .bottom: + NSLayoutConstraint.constraintPinSubview(borderLine, pinTop: false, pinBottom: true, pinLeft: false, pinRight: false) + NSLayoutConstraint.constraintPinView(borderLine, heightConstraint: true, heightConstant: borderLineWidth, widthConstraint: true, widthConstant: borderLineLengh) + NSLayoutConstraint.constraintPinSubview(borderLine, pinCenterX: true, pinCenterY: false) + + case .right: + NSLayoutConstraint.constraintPinSubview(borderLine, pinTop: false, pinBottom: false, pinLeft: false, pinRight: true) + NSLayoutConstraint.constraintPinView(borderLine, heightConstraint: true, heightConstant: borderLineLengh, widthConstraint: true, widthConstant: borderLineWidth) + NSLayoutConstraint.constraintPinSubview(borderLine, pinCenterX: false, pinCenterY: true) + + default: + break + } + + borderLine.backgroundColor = color + } + + class func mfStylePageControl(_ pageControl: UIPageControl?) { + + pageControl?.pageIndicatorTintColor = .mfLighterGray() + pageControl?.currentPageIndicatorTintColor = .mfRed() + } + + class func styleTextField(_ textField: UITextField) { + + textField.font = fontForTextField() + // As per AKQA + /* If the length of the text field exceeds the amount of space, the size of the text drops down. + So, the entire line of copy can be read. + 16 point font size is the lowest recommended size. + */ + textField.minimumFontSize = 16 + textField.adjustsFontSizeToFitWidth = true // default is NO. if YES, text will shrink to minFontSize along baseline + } + /* + class func setGradientTo(_ label: UILabel, withColors colors: [AnyHashable]) { + + var textSize: CGSize? = nil + + if let font = UIFont(name: label.font.fontName, size: label.font.lineHeight) { + textSize = label.text?.size(withAttributes: [NSAttributedString.Key.baselineOffset: 0, + NSAttributedString.Key.font: font]) + } + + let width = (textSize?.width ?? 0.0) > 1024 ? 1024 : textSize?.width ?? 0.0 // max 1024 due to Core Graphics limitations + let height = (textSize?.height ?? 0.0) > 1024 ? 1024 : textSize?.height ?? 0.0 // max 1024 due to Core Graphics limitations + + // create a new bitmap image context + UIGraphicsBeginImageContext(CGSize(width: width, height: height)) + + let context = UIGraphicsGetCurrentContext() + + // push context to make it current (need to do this manually because we are not drawing in a UIView) + if let context = context { + UIGraphicsPushContext(context) + } + + var glossGradient: CGGradient? + var rgbColorspace: CGColorSpace? + let num_locations = colors.count + var locations = [CGFloat](repeating: 0.0, count: colors.count) + let components = [CGFloat](repeating: 0.0, count: colors.count * 4) + var componentIndex = 0 + + for i in 0.. UIImage? { + + UIGraphicsBeginImageContextWithOptions(image?.size ?? CGSize.zero, _: true, _: 1.0) + let imageRect = CGRect(x: 0, y: 0, width: image?.size.width ?? 0.0, height: image?.size.height ?? 0.0) + + // Draw the image with the luminosity blend mode. + // On top of a white background, this will give a black and white image. + image?.draw(in: imageRect, blendMode: .luminosity, alpha: 1.0) + + // Get the resulting image. + let filteredImage = UIGraphicsGetImageFromCurrentImageContext() + UIGraphicsEndImageContext() + + return filteredImage + } + /* + class func getCountTime(_ leftTime: Int, timeformat timeFormat: String?, time timeUnit: MFTimeFormatUnit, timeSuffix suffix: String?) -> String? { + + var seconds = leftTime % 60 + var minutes = (leftTime / 60) % 60 + var hours = (leftTime / 3600) % 24 + let days = leftTime / 86400 + + guard let times = timeFormat?.components(separatedBy: ":") else { return nil } + var timeString = "" + + if times.contains("DD") { + timeString += String(format: "%02ld", days) + + if timeUnit == .mfTimeFormatNormal { + let dayKey = (days <= 1) ? "CountDownDay" : "CountDownDays" + let dayUnit = MVMCoreUIUtility.hardcodedString(withKey: dayKey) + timeString += dayUnit! + + } else if timeUnit == MFTimeFormatColon && times?.last != "DD" { + timeString += " : " + } + + if times.last != "DD" && suffix != nil { + timeString += suffix ?? "" + } + } + + if times.contains("HH") { + if !times.contains("DD") { + hours = leftTime / 3600 + } + + timeString += String(format: "%02d", hours) + + if timeUnit == .mfTimeFormatNormal { + let hourKey = (hours <= 1) ? "CountDownHour" : "CountDownHours" + let hourUnit = MVMCoreUIUtility.hardcodedString(withKey: hourKey)! + timeString += hourUnit + + } else if timeUnit == MFTimeFormatColon && times?.last != "HH" { + timeString += " : " + } + + if times.last != "HH" && suffix != nil { + timeString += suffix ?? "" + } + } + + if times.contains("MM") { + if !times.contains("HH") { + if !times.contains("DD") { + minutes = leftTime / 60 + } else { + minutes = (leftTime - days * 86400) / 60 + } + } + + timeString += String(format: "%02d", minutes) + + if times.contains("SS") { + if !times.contains("MM") { + if !times.contains("HH") { + if !times.contains("DD") { + seconds = leftTime + } else { + seconds = leftTime % 86400 + } + } else { + seconds = leftTime % 3600 + } + } + + timeString += String(format: "%02d", seconds) + + if timeUnit == .mfTimeFormatNormal { + let secondKey = (seconds <= 1) ? "CountDownSec" : "CountDownSecs" + let secondUnit = MVMCoreUIUtility.hardcodedString(withKey: secondKey) + timeString += secondUnit! + } + } + return timeString + } + } + */ +} From 1957f4d354a6bf6cb8d31764edc5a0a1942fbe38 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 1 Apr 2020 14:47:47 -0400 Subject: [PATCH 02/31] pulling in new changes --- MVMCoreUI/Styles/Styler.swift | 318 ++++++++++++++++++++++++++++++++++ 1 file changed, 318 insertions(+) diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index f5b90149..0a38e6f0 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -214,6 +214,170 @@ public class Styler { } } + //-------------------------------------------------- + // MARK: - 3.0 fonts + //-------------------------------------------------- + + class func getMVA3FontSize(_ size: CGFloat, bold isBold: Bool) -> UIFont { + 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) + } + } + } + + class func fontTitle2XLarge(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 36 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: true) + } + + class func fontTitle2XLarge() -> UIFont { + return self.fontTitle2XLarge(true) + } + + class func fontTitleXLarge(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 32 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: true) + } + + class func fontTitleXLarge() -> UIFont { + return self.fontTitleXLarge(true) + } + + class func fontBoldTitleLarge(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 24 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: true) + } + + class func fontBoldTitleLarge() -> UIFont { + return self.fontBoldTitleLarge(true) + } + + class func fontRegularTitleLarge(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 24 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: false) + } + + class func fontRegularTitleLarge() -> UIFont { + return self.fontRegularTitleLarge(true) + } + + class func fontBoldTitleMedium(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 20 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: true) + } + + class func fontBoldTitleMedium() -> UIFont { + return self.fontBoldTitleMedium(true) + } + + class func fontRegularTitleMedium(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 20 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: false) + } + + class func fontRegularTitleMedium() -> UIFont { + return self.fontRegularTitleMedium(true) + } + + class func fontBoldBodyLarge(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 16 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: true) + } + + class func fontBoldBodyLarge() -> UIFont { + return self.fontBoldBodyLarge(true) + } + + class func fontRegularBodyLarge(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 16 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: false) + } + + class func fontRegularBodyLarge() -> UIFont { + return self.fontRegularBodyLarge(true) + } + + class func fontBoldBodySmall(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 13 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: true) + } + + class func fontBoldBodySmall() -> UIFont { + return self.fontBoldBodySmall(true) + } + + class func fontRegularBodySmall(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 13 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: false) + } + + class func fontRegularBodySmall() -> UIFont { + return self.fontRegularBodySmall(true) + } + + class func fontBoldMicro(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 11 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: true) + } + + class func fontBoldMicro() -> UIFont { + return self.fontBoldMicro(true) + } + + class func fontRegularMicro(_ genericScaling: Bool) -> UIFont { + var size: CGFloat = 11 + if genericScaling { + size = self.sizeFontGeneric(forCurrentDevice: size) + } + return self.getMVA3FontSize(size, bold: false) + } + + class func fontRegularMicro() -> UIFont { + return self.fontRegularMicro(true) + } + //-------------------------------------------------- // MARK: - Fonts //-------------------------------------------------- @@ -306,6 +470,160 @@ public class Styler { return MFFonts.mfFont55Rg(size) } + //-------------------------------------------------- + // MARK: - 3.0 Styles + //-------------------------------------------------- + + class func styleLabelTitle2XLarge(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontTitle2XLarge(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelTitle2XLarge(_ label: UILabel) { + self.styleLabelTitle2XLarge(label, genericScaling: true) + } + + class func styleLabelTitleXLarge(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontTitleXLarge(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelTitleXLarge(_ label: UILabel) { + self.styleLabelTitleXLarge(label, genericScaling: true) + } + + class func styleLabelBoldTitleLarge(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontBoldTitleLarge(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelBoldTitleLarge(_ label: UILabel) { + self.styleLabelBoldTitleLarge(label, genericScaling: true) + } + + class func styleLabelRegularTitleLarge(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontRegularTitleLarge(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelRegularTitleLarge(_ label: UILabel) { + self.styleLabelBoldTitleLarge(label, genericScaling: true) + } + + class func styleLabelBoldTitleMedium(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontBoldTitleMedium(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelBoldTitleMedium(_ label: UILabel) { + self.styleLabelBoldTitleMedium(label, genericScaling: true) + } + + class func styleLabelRegularTitleMedium(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontRegularTitleMedium(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelRegularTitleMedium(_ label: UILabel) { + self.styleLabelRegularTitleMedium(label, genericScaling: true) + } + + class func styleLabelBoldBodyLarge(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontBoldBodyLarge(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelBoldBodyLarge(_ label: UILabel) { + self.styleLabelBoldBodyLarge(label, genericScaling: true) + } + + class func styleLabelRegularBodyLarge(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontRegularBodyLarge(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelRegularBodyLarge(_ label: UILabel) { + self.styleLabelRegularBodyLarge(label, genericScaling: true) + } + + class func styleLabelBoldBodySmall(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontBoldBodySmall(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelBoldBodySmall(_ label: UILabel) { + self.styleLabelBoldBodySmall(label, genericScaling: true) + } + + class func styleLabelRegularBodySmall(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontRegularBodySmall(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelRegularBodySmall(_ label: UILabel) { + self.styleLabelRegularBodySmall(label, genericScaling: true) + } + + class func styleLabelBoldMicro(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontBoldMicro(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelBoldMicro(_ label: UILabel) { + self.styleLabelBoldMicro(label, genericScaling: true) + } + + class func styleLabelRegularMicro(_ label: UILabel, genericScaling: Bool) { + label.font = MFStyler.fontRegularMicro(genericScaling) + label.textColor = UIColor.black + } + + class func styleLabelRegularMicro(_ label: UILabel) { + self.styleLabelRegularMicro(label, genericScaling: true) + } + + class func styleMVA3Label(_ label: UILabel, withStyle style: String?, genericScaling: Bool) -> Bool { + if (style == "Title2XLarge") { + self.styleLabelTitle2XLarge(label, genericScaling: genericScaling) + return true + } else if (style == "TitleXLarge") { + self.styleLabelTitleXLarge(label, genericScaling: genericScaling) + return true + } else if (style == "BoldTitleLarge") { + self.styleLabelBoldTitleLarge(label, genericScaling: genericScaling) + return true + } else if (style == "RegularTitleLarge") { + self.styleLabelRegularTitleLarge(label, genericScaling: genericScaling) + return true + } else if (style == "BoldTitleMedium") { + self.styleLabelBoldTitleMedium(label, genericScaling: genericScaling) + return true + } else if (style == "RegularTitleMedium") { + self.styleLabelRegularTitleMedium(label, genericScaling: genericScaling) + return true + } else if (style == "BoldBodyLarge") { + self.styleLabelBoldBodyLarge(label, genericScaling: genericScaling) + return true + } else if (style == "RegularBodyLarge") { + self.styleLabelRegularBodyLarge(label, genericScaling: genericScaling) + return true + } else if (style == "BoldBodySmall") { + self.styleLabelBoldBodySmall(label, genericScaling: genericScaling) + return true + } else if (style == "RegularBodySmall") { + self.styleLabelRegularBodySmall(label, genericScaling: genericScaling) + return true + } else if (style == "BoldMicro") { + self.styleLabelBoldMicro(label, genericScaling: genericScaling) + return true + } else if (style == "RegularMicro") { + self.styleLabelRegularMicro(label, genericScaling: genericScaling) + return true + } else { + return false + } + } + //-------------------------------------------------- // MARK: - Styles //-------------------------------------------------- From a8e411472fe65c1208a9b474abb75d62f72eea49 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 1 Apr 2020 16:40:58 -0400 Subject: [PATCH 03/31] dramatic alteration --- MVMCoreUI.xcodeproj/project.pbxproj | 4 + MVMCoreUI/Styles/Padding.swift | 74 ++ MVMCoreUI/Styles/Styler.swift | 1407 ++------------------------- 3 files changed, 169 insertions(+), 1316 deletions(-) create mode 100644 MVMCoreUI/Styles/Padding.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 3f13e17b..ddb3307c 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -88,6 +88,7 @@ 0A41BA7F23453A6400D4C0BC /* TextEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A41BA7E23453A6400D4C0BC /* TextEntryField.swift */; }; 0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */; }; 0A6682AA2435125F00AD3CA1 /* Styler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682A92435125F00AD3CA1 /* Styler.swift */; }; + 0A6682AC243531C300AD3CA1 /* Padding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682AB243531C300AD3CA1 /* Padding.swift */; }; 0A69F611241BDEA700F7231B /* RuleAnyRequiredModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */; }; 0A6BF4722360C56C0028F841 /* BaseDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */; }; 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; }; @@ -474,6 +475,7 @@ 0A41BA7E23453A6400D4C0BC /* TextEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextEntryField.swift; sourceTree = ""; }; 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleGuidelinesProtocol.swift; sourceTree = ""; }; 0A6682A92435125F00AD3CA1 /* Styler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Styler.swift; sourceTree = ""; }; + 0A6682AB243531C300AD3CA1 /* Padding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Padding.swift; sourceTree = ""; }; 0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleAnyRequiredModel.swift; sourceTree = ""; }; 0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseDropdownEntryField.swift; sourceTree = ""; }; 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyButton.swift; sourceTree = ""; }; @@ -1469,6 +1471,7 @@ D29DF13821E68636003B2FB9 /* MFStyler.h */, D29DF13921E68637003B2FB9 /* MFStyler.m */, 0A6682A92435125F00AD3CA1 /* Styler.swift */, + 0A6682AB243531C300AD3CA1 /* Padding.swift */, ); path = Styles; sourceTree = ""; @@ -2051,6 +2054,7 @@ 0A7EF85D23D8A95600B2AAD1 /* TextEntryFieldModel.swift in Sources */, D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */, 01EB368F23609801006832FA /* LabelModel.swift in Sources */, + 0A6682AC243531C300AD3CA1 /* Padding.swift in Sources */, 942C378E2412F5B60066E45E /* ModalMoleculeStackTemplate.swift in Sources */, 8D4687E4242E2DF300802879 /* ListFourColumnDataUsageListItem.swift in Sources */, 01F2A03223A4498200D954D8 /* CaretLinkModel.swift in Sources */, diff --git a/MVMCoreUI/Styles/Padding.swift b/MVMCoreUI/Styles/Padding.swift new file mode 100644 index 00000000..bdd65837 --- /dev/null +++ b/MVMCoreUI/Styles/Padding.swift @@ -0,0 +1,74 @@ +// +// Padding.swift +// MVMCoreUI +// +// Created by Kevin Christiano on 4/1/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + + +public struct Padding { + + public static let One: CGFloat = 6 + public static let Two: CGFloat = 12 + public static let Three: CGFloat = 18 + public static let Four: CGFloat = 24 + public static let Five: CGFloat = 30 + public static let Six: CGFloat = 36 + public static let Seven: CGFloat = 42 + public static let Eight: CGFloat = 48 + public static let Nine: CGFloat = 54 + public static let Ten: CGFloat = 60 + + public static let TableCellParagraphSpace: CGFloat = 3 + public static let FooterLabelParagraphSpace: CGFloat = 4 + public static let WebViewInset: CGFloat = 8 + public static let HeightTableSeperatorHeight: CGFloat = 1 + public static let MFHeightForSwitch: CGFloat = 22 + public static let MFWidthForSwitch: CGFloat = 42 + public static let DisableOppacity: CGFloat = 0.5 + public static let PaymentMethodViewHeightWidthMultiplier: CGFloat = 0.55 + public static let MinCellHeight: CGFloat = 96 + public static let HeightIphone5: CGFloat = 568 + public static let DefaultOptionCellHeight: CGFloat = 120 + public static let PromoViewHeight: CGFloat = 41.9 + public static let BetweenFields: CGFloat = 24 + public static let LabelWithInternalButtonLineSpace: CGFloat = 2 + public static let PrimaryButtonTop: CGFloat = 36 + + public struct Default { + public static let Standard: CGFloat = 24 + public static let HorizontalSpacing: CGFloat = 32 + public static let VerticalSpacing: CGFloat = 32 + public static let VerticalSpacing3: CGFloat = 24 + + public static var HorizontalPaddingForApplicationWidth: CGFloat { + return MFSizeObject(scalingStandardSize: PaddingDefaultHorizontalSpacing)?.getValueBasedOnApplicationWidth() ?? 0 + } + + public static var VerticalPaddingForApplicationWidth: CGFloat { + return MFSizeObject(scalingStandardSize: PaddingDefaultVerticalSpacing)?.getValueBasedOnApplicationWidth() ?? 0 + } + + public static func horizontalPadding(forSize size: CGFloat) -> CGFloat { + return MFSizeObject(scalingStandardSize: PaddingDefaultHorizontalSpacing)?.getValueBased(onSize: size) ?? 0 + } + + public static func verticalPadding(forSize size: CGFloat) -> CGFloat { + return MFSizeObject(scalingStandardSize: PaddingDefaultVerticalSpacing)?.getValueBased(onSize: size) ?? 0 + } + } + + public struct Horizontal { + public static let HeadlineWhiteView: CGFloat = 60 + public static let Large: CGFloat = 72 + public static let BetweenRelatedItems: CGFloat = 16 + } + + public struct Vertical { + public static let WhiteGrayView: CGFloat = 72 + public static let HeadlineAlternate: CGFloat = 48 + } +} diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 0a38e6f0..a43bc47a 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -9,6 +9,7 @@ import Foundation import MVMCore + public protocol VogueProtocol { } @@ -23,56 +24,13 @@ public protocol VogueTextProtocol: VogueProtocol { } -struct Padding { - - static let One: CGFloat = 6 - static let Two: CGFloat = 12 - static let Three: CGFloat = 18 - static let Four: CGFloat = 24 - static let Five: CGFloat = 30 - static let Six: CGFloat = 36 - static let Seven: CGFloat = 42 - static let Eight: CGFloat = 48 - static let Nine: CGFloat = 54 - static let Ten: CGFloat = 60 - - static let TableCellParagraphSpace: CGFloat = 3 - static let FooterLabelParagraphSpace: CGFloat = 4 - static let WebViewInset: CGFloat = 8 - static let HeightTableSeperatorHeight: CGFloat = 1 - static let MFHeightForSwitch: CGFloat = 22 - static let MFWidthForSwitch: CGFloat = 42 - static let DisableOppacity: CGFloat = 0.5 - static let PaymentMethodViewHeightWidthMultiplier: CGFloat = 0.55 - static let MinCellHeight: CGFloat = 96 - static let HeightIphone5: CGFloat = 568 - static let DefaultOptionCellHeight: CGFloat = 120 - static let PromoViewHeight: CGFloat = 41.9 - static let BetweenFields: CGFloat = 24 - static let LabelWithInternalButtonLineSpace: CGFloat = 2 - static let PrimaryButtonTop: CGFloat = 36 - - struct Default { - static let Standard: CGFloat = 24 - static let HorizontalSpacing: CGFloat = 32 - static let VerticalSpacing: CGFloat = 32 - static let VerticalSpacing3: CGFloat = 24 - } - - struct Horizontal { - static let HeadlineWhiteView: CGFloat = 60 - static let Large: CGFloat = 72 - static let BetweenRelatedItems: CGFloat = 16 - } - - struct Vertical { - static let WhiteGrayView: CGFloat = 72 - static let HeadlineAlternate: CGFloat = 48 - } -} -public class Styler { +open class Styler { + + //-------------------------------------------------- + // MARK: - Enums + //-------------------------------------------------- enum MFViewBorder: Int { case top @@ -81,63 +39,81 @@ public class Styler { case right } - enum MFTimeFormatUnit: Int { - case mfTimeFormatColon = 0 //!{days} : {hour} : {minutes} : {seconds} - case mfTimeFormatNormal = 1 // will end with days hours minutes seconds, when left days less than 2, it will change to 'day' - } - - //-------------------------------------------------- - // MARK: - Enum - //-------------------------------------------------- - - public enum Style: String { - case H1 - case H2 - case H3 - case H32 - case B1 - case B2 - case B3 - case B20 + public enum FontStyle: String { + case Title2XLarge + case TitleXLarge + case BoldTitleLarge + case RegularTitleLarge + case BoldTitleMedium + case RegularTitleMedium + case BoldBodyLarge + case RegularBodyLarge + case BoldBodySmall + case RegularBodySmall + case BoldMicro + case RegularMicro - func font(_ genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 0 + func pointSize() -> CGFloat { + switch self { + case .Title2XLarge: + return 36 + + case .TitleXLarge: + return 32 + + case .BoldTitleLarge, + .RegularTitleLarge: + return 24 + + case .BoldTitleMedium, + .RegularTitleMedium: + return 20 + + case .BoldBodyLarge, + .RegularBodyLarge: + return 16 + + case .BoldBodySmall, + .RegularBodySmall: + return 13 + + case .BoldMicro, .RegularMicro: + return 11 + } + } + + func isBold() -> Bool { switch self { - case .H1: - size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 40 - return MFFonts.mfFont75Bd(size) + case .Title2XLarge, + .TitleXLarge, + .RegularTitleLarge, + .RegularTitleMedium, + .RegularBodyLarge, + .RegularBodySmall, + .RegularMicro: + return false - case .H2: - size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 25 - return MFFonts.mfFont75Bd(size) - - case .H3: - size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 18 - return MFFonts.mfFont75Bd(size) - - case .H32: - size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 32 - return MFFonts.mfFont75Bd(size) - - case .B1: - size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 13 - return MFFonts.mfFont75Bd(size) - - case .B2: - size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 13 - return MFFonts.mfFont55Rg(size) - - case .B3: - size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 11 - return MFFonts.mfFont55Rg(size) - - case .B20: - size = genericScaling ? sizeFontGeneric(forCurrentDevice: size) : 20 - return MFFonts.mfFont55Rg(size) + case .BoldTitleLarge, + .BoldTitleMedium, + .BoldBodyLarge, + .BoldBodySmall, + .BoldMicro: + return true } } + + func getFont(_ genericScaling: Bool = true) -> UIFont? { + + let size = genericScaling ? sizeFontGeneric(forCurrentDevice: pointSize()) : pointSize() + return getMVA3FontSize(size, bold: isBold()) + } + + func styleLabel(_ label: UILabel, genericScaling: Bool = true) { + + label.font = getFont(genericScaling) + label.textColor = .black + } } public enum Tier { @@ -156,7 +132,7 @@ public class Styler { } class func splitTextFieldWidth(forViewWidth width: CGFloat) -> CGFloat { - return (width - CGFloat(PaddingOne)) / 2 - defaultHorizontalPaddingForApplicationWidth() + return (width - CGFloat(PaddingOne)) / 2 - Padding.Default.HorizontalPaddingForApplicationWidth } class func sizeObjectGeneric(forCurrentDevice size: CGFloat) -> MFSizeObject? { @@ -175,29 +151,9 @@ public class Styler { // MARK: - Spacing //-------------------------------------------------- - class func defaultHorizontalPaddingForApplicationWidth() -> CGFloat { - return MFSizeObject(scalingStandardSize: PaddingDefaultHorizontalSpacing)?.getValueBasedOnApplicationWidth() ?? 0 - } - - class func defaultVerticalPaddingForApplicationWidth() -> CGFloat { - return MFSizeObject(scalingStandardSize: PaddingDefaultVerticalSpacing)?.getValueBasedOnApplicationWidth() ?? 0 - } - - class func defaultHorizontalPadding(forSize size: CGFloat) -> CGFloat { - return MFSizeObject(scalingStandardSize: PaddingDefaultHorizontalSpacing)?.getValueBased(onSize: size) ?? 0 - } - - class func defaultVerticalPadding(forSize size: CGFloat) -> CGFloat { - return MFSizeObject(scalingStandardSize: PaddingDefaultVerticalSpacing)?.getValueBased(onSize: size) ?? 0 - } - - class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat) { - setDefaultMarginsFor(view, size: size, horizontal: true, vertical: false) - } - - class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat, horizontal: Bool, vertical: Bool) { + class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat, horizontal: Bool = true, vertical: Bool = false) { - let horizontalPadding: CGFloat = horizontal ? defaultHorizontalPadding(forSize: size) : 0 + let horizontalPadding: CGFloat = horizontal ? Padding.Default.horizontalPadding(forSize: size) : 0 let verticalPadding: CGFloat = vertical ? PaddingDefaultVerticalSpacing3 : 0 DispatchQueue.main.async { @@ -207,7 +163,7 @@ public class Styler { class func setMarginsFor(_ view: UIView?, size: CGFloat, defaultHorizontal horizontal: Bool, top: CGFloat, bottom: CGFloat) { - let horizontalPadding: CGFloat = horizontal ? defaultHorizontalPadding(forSize: size) : 0 + let horizontalPadding: CGFloat = horizontal ? Padding.Default.horizontalPadding(forSize: size) : 0 DispatchQueue.main.async { MVMCoreUIUtility.setMarginsFor(view, leading: horizontalPadding, top: top, trailing: horizontalPadding, bottom: bottom) @@ -219,1023 +175,27 @@ public class Styler { //-------------------------------------------------- class func getMVA3FontSize(_ size: CGFloat, bold isBold: Bool) -> UIFont { + if isBold { - if size >= 15 { - return MFFonts.mfFontDSBold(size) - } else { - return MFFonts.mfFontTXBold(size) - } + return size >= 15 ? MFFonts.mfFontDSBold(size) : MFFonts.mfFontTXBold(size) + } else { - if size >= 15 { - return MFFonts.mfFontDSRegular(size) - } else { - return MFFonts.mfFontTXRegular(size) - } + return size >= 15 ? MFFonts.mfFontDSRegular(size) : MFFonts.mfFontTXRegular(size) } } - class func fontTitle2XLarge(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 36 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: true) - } - - class func fontTitle2XLarge() -> UIFont { - return self.fontTitle2XLarge(true) - } - - class func fontTitleXLarge(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 32 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: true) - } - - class func fontTitleXLarge() -> UIFont { - return self.fontTitleXLarge(true) - } - - class func fontBoldTitleLarge(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 24 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: true) - } - - class func fontBoldTitleLarge() -> UIFont { - return self.fontBoldTitleLarge(true) - } - - class func fontRegularTitleLarge(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 24 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: false) - } - - class func fontRegularTitleLarge() -> UIFont { - return self.fontRegularTitleLarge(true) - } - - class func fontBoldTitleMedium(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 20 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: true) - } - - class func fontBoldTitleMedium() -> UIFont { - return self.fontBoldTitleMedium(true) - } - - class func fontRegularTitleMedium(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 20 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: false) - } - - class func fontRegularTitleMedium() -> UIFont { - return self.fontRegularTitleMedium(true) - } - - class func fontBoldBodyLarge(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 16 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: true) - } - - class func fontBoldBodyLarge() -> UIFont { - return self.fontBoldBodyLarge(true) - } - - class func fontRegularBodyLarge(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 16 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: false) - } - - class func fontRegularBodyLarge() -> UIFont { - return self.fontRegularBodyLarge(true) - } - - class func fontBoldBodySmall(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 13 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: true) - } - - class func fontBoldBodySmall() -> UIFont { - return self.fontBoldBodySmall(true) - } - - class func fontRegularBodySmall(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 13 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: false) - } - - class func fontRegularBodySmall() -> UIFont { - return self.fontRegularBodySmall(true) - } - - class func fontBoldMicro(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 11 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: true) - } - - class func fontBoldMicro() -> UIFont { - return self.fontBoldMicro(true) - } - - class func fontRegularMicro(_ genericScaling: Bool) -> UIFont { - var size: CGFloat = 11 - if genericScaling { - size = self.sizeFontGeneric(forCurrentDevice: size) - } - return self.getMVA3FontSize(size, bold: false) - } - - class func fontRegularMicro() -> UIFont { - return self.fontRegularMicro(true) - } - - //-------------------------------------------------- - // MARK: - Fonts - //-------------------------------------------------- - - class func fontH1(_ genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 40 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func fontH2(_ genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 25 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func fontH3(_ genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 18 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func fontH32(_ genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 32 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func fontB1(_ genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 13 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func fontB2(_ genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 13 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func fontB3(_ genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 11 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func fontB20(_ genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 20 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - //-------------------------------------------------- - // MARK: - 3.0 Styles - //-------------------------------------------------- - - class func styleLabelTitle2XLarge(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontTitle2XLarge(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelTitle2XLarge(_ label: UILabel) { - self.styleLabelTitle2XLarge(label, genericScaling: true) - } - - class func styleLabelTitleXLarge(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontTitleXLarge(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelTitleXLarge(_ label: UILabel) { - self.styleLabelTitleXLarge(label, genericScaling: true) - } - - class func styleLabelBoldTitleLarge(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontBoldTitleLarge(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelBoldTitleLarge(_ label: UILabel) { - self.styleLabelBoldTitleLarge(label, genericScaling: true) - } - - class func styleLabelRegularTitleLarge(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontRegularTitleLarge(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelRegularTitleLarge(_ label: UILabel) { - self.styleLabelBoldTitleLarge(label, genericScaling: true) - } - - class func styleLabelBoldTitleMedium(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontBoldTitleMedium(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelBoldTitleMedium(_ label: UILabel) { - self.styleLabelBoldTitleMedium(label, genericScaling: true) - } - - class func styleLabelRegularTitleMedium(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontRegularTitleMedium(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelRegularTitleMedium(_ label: UILabel) { - self.styleLabelRegularTitleMedium(label, genericScaling: true) - } - - class func styleLabelBoldBodyLarge(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontBoldBodyLarge(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelBoldBodyLarge(_ label: UILabel) { - self.styleLabelBoldBodyLarge(label, genericScaling: true) - } - - class func styleLabelRegularBodyLarge(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontRegularBodyLarge(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelRegularBodyLarge(_ label: UILabel) { - self.styleLabelRegularBodyLarge(label, genericScaling: true) - } - - class func styleLabelBoldBodySmall(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontBoldBodySmall(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelBoldBodySmall(_ label: UILabel) { - self.styleLabelBoldBodySmall(label, genericScaling: true) - } - - class func styleLabelRegularBodySmall(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontRegularBodySmall(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelRegularBodySmall(_ label: UILabel) { - self.styleLabelRegularBodySmall(label, genericScaling: true) - } - - class func styleLabelBoldMicro(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontBoldMicro(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelBoldMicro(_ label: UILabel) { - self.styleLabelBoldMicro(label, genericScaling: true) - } - - class func styleLabelRegularMicro(_ label: UILabel, genericScaling: Bool) { - label.font = MFStyler.fontRegularMicro(genericScaling) - label.textColor = UIColor.black - } - - class func styleLabelRegularMicro(_ label: UILabel) { - self.styleLabelRegularMicro(label, genericScaling: true) - } - - class func styleMVA3Label(_ label: UILabel, withStyle style: String?, genericScaling: Bool) -> Bool { - if (style == "Title2XLarge") { - self.styleLabelTitle2XLarge(label, genericScaling: genericScaling) - return true - } else if (style == "TitleXLarge") { - self.styleLabelTitleXLarge(label, genericScaling: genericScaling) - return true - } else if (style == "BoldTitleLarge") { - self.styleLabelBoldTitleLarge(label, genericScaling: genericScaling) - return true - } else if (style == "RegularTitleLarge") { - self.styleLabelRegularTitleLarge(label, genericScaling: genericScaling) - return true - } else if (style == "BoldTitleMedium") { - self.styleLabelBoldTitleMedium(label, genericScaling: genericScaling) - return true - } else if (style == "RegularTitleMedium") { - self.styleLabelRegularTitleMedium(label, genericScaling: genericScaling) - return true - } else if (style == "BoldBodyLarge") { - self.styleLabelBoldBodyLarge(label, genericScaling: genericScaling) - return true - } else if (style == "RegularBodyLarge") { - self.styleLabelRegularBodyLarge(label, genericScaling: genericScaling) - return true - } else if (style == "BoldBodySmall") { - self.styleLabelBoldBodySmall(label, genericScaling: genericScaling) - return true - } else if (style == "RegularBodySmall") { - self.styleLabelRegularBodySmall(label, genericScaling: genericScaling) - return true - } else if (style == "BoldMicro") { - self.styleLabelBoldMicro(label, genericScaling: genericScaling) - return true - } else if (style == "RegularMicro") { - self.styleLabelRegularMicro(label, genericScaling: genericScaling) - return true - } else { - return false - } - } - //-------------------------------------------------- // MARK: - Styles //-------------------------------------------------- - class func styleLabel(_ label: VogueTextProtocol, withStyle style: Style, genericScaling: Bool) { - - switch style { - case .H1: - styleLabelH1(label, genericScaling: genericScaling) - - case .H2: - styleLabelH2(label, genericScaling: genericScaling) - - case .H3: - styleLabelH3(label, genericScaling: genericScaling) - - case .H32: - styleLabelH32(label, genericScaling: genericScaling) - - case .B1: - styleLabelB1(label, genericScaling: genericScaling) - - case .B2: - styleLabelB2(label, genericScaling: genericScaling) - - case .B3: - styleLabelB3(label, genericScaling: genericScaling) - - case .B20: - styleLabelB20(label, genericScaling: genericScaling) - } - } - - class func styleLabel(_ label: UILabel, withStyle style: Style) { - styleLabel(label, withStyle: style, genericScaling: true) - } - - class func styleLabelH1(_ label: VogueTextProtocol, genericScaling: Bool = true) { - - label.styleTextColor(.black) - - if let h1 = fontH1(genericScaling) { - label.styleFont(h1) - } - } - - class func styleLabelH2(_ label: VogueTextProtocol, genericScaling: Bool = true) { - - label.styleTextColor(.black) - - if let h2 = fontH2(genericScaling) { - label.styleFont(h2) - } - } - - class func styleLabelH3(_ label: VogueTextProtocol, genericScaling: Bool = true) { - - label.styleTextColor(.black) - - if let h3 = fontH3(genericScaling) { - label.styleFont(h3) - } - } - - class func styleLabelH32(_ label: VogueTextProtocol, genericScaling: Bool = true) { - - label.styleTextColor(.black) - - if let h32 = fontH32(genericScaling) { - label.styleFont(h32) - } - } - - class func styleLabelB1(_ label: VogueTextProtocol, genericScaling: Bool = true) { - - label.styleTextColor(.black) - - if let b1 = fontB1(genericScaling) { - label.styleFont(b1) - } - } - - class func styleLabelB2(_ label: VogueTextProtocol, genericScaling: Bool = true) { - - label.styleTextColor(.black) - - if let b2 = fontB2(genericScaling) { - label.styleFont(b2) - } - } - - class func styleLabelB2(_ label: UILabel, size: CGFloat, genericScaling: Bool = true) { - label.font = fontForBody(withSize: size, genericScaling: genericScaling) - } - - class func styleLabelB3(_ label: VogueTextProtocol, genericScaling: Bool = true) { - - label.styleTextColor(.mfBackgroundGray()) - - if let b3 = fontB3(genericScaling) { - label.styleFont(b3) - } - } - - class func styleLabelB20(_ label: VogueTextProtocol, genericScaling: Bool = true) { - - label.styleTextColor(.black) - - if let b20 = fontB20(genericScaling) { - label.styleFont(b20) - } - } - - class func styleLabelTextStyle2(_ label: VogueTextProtocol, genericScaling: Bool = true) { - - label.styleTextColor(.mfBattleshipGrey()) - - if let b2 = fontB2(genericScaling) { - label.styleFont(b2) - } - } - - class func fontForBody(withSize size: CGFloat, genericScaling: Bool) -> UIFont? { - - var size = size - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func fontForBody(withSize size: CGFloat, forWidth width: CGFloat) -> UIFont? { - - let size = sizeObjectGeneric(forCurrentDevice: size)?.getValueBased(onSize: width) ?? size - - return MFFonts.mfFont55Rg(size) - } - - //-------------------------------------------------- - // MARK: - 1.0 Fonts - //-------------------------------------------------- - - class func font(forPlan genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 100 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func font(forBiggerHeadLine genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 48 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func font(forHeadlineSmall genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 15 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func font(forHeadlineSmall2 genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 16 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func fontForHeadlineSmall2(forWidth size: CGFloat) -> UIFont? { - - var pointSize: CGFloat = 16 - pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) - - return MFFonts.mfFont75Bd(pointSize) - } - - class func fontB1(forWidth size: CGFloat) -> UIFont? { - - var pointSize: CGFloat = 13 - pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) - - return MFFonts.mfFont75Bd(pointSize) - } - - //-------------------------------------------------- - // MARK: - 1.0 Styles - //-------------------------------------------------- - - class func styleFeedCardTitleLabel(_ label: UILabel) { - - label.font = Styler.fontForFeedCardTitle() - label.textColor = .black - } - - class func styleFeedCardTagLabel(_ label: UILabel) { - - label.font = Styler.fontB3() - label.textColor = .mfBrownishGrey() - } - - class func styleStandardSeparatorView(_ view: UIView) { - - view.backgroundColor = .mfBackgroundGray() - } - - class func styleLabelHeadlineSmall(_ label: UILabel, genericScaling: Bool) { - - label.font = Styler.font(forHeadlineSmall: genericScaling) - label.textColor = .black - } - - class func styleFeedCardTitleLabel(_ label: UILabel, genericScaling: Bool) { - - label.font = Styler.font(forFeedCardTitle: genericScaling) - label.textColor = UIColor.black - } - - class func styleFeedCardTagLabel(_ label: UILabel, genericScaling: Bool) { - - label.font = Styler.fontB3(genericScaling) - label.textColor = UIColor.mfBrownishGrey() - } - - class func fontB2(forWidth size: CGFloat) -> UIFont? { - - var pointSize: CGFloat = 13 - - pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) - - return MFFonts.mfFont55Rg(pointSize) - } - - class func fontforChatText(_ genericScaling: Bool = false) -> UIFont? { - - var size: CGFloat = 14 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func font(forAccountLandingGreeting genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 16 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func font(forProgressBarBottomLabel genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 10 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func font(forFeedCardTitle genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 16 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func font(forPrimaryButton genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 14 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func fontForPrimaryButton(forWidth size: CGFloat) -> UIFont? { - - var pointSize: CGFloat = 14 - pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) - return MFFonts.mfFont75Bd(pointSize) - } - - class func font(forSmallButton genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 11 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func fontForSmallButton(forWidth size: CGFloat) -> UIFont? { - - var pointSize: CGFloat = 11 - pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) - - return MFFonts.mfFont75Bd(pointSize) - } - - class func font(forTextField genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 16 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func font(forTextFieldUnderLabel genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 12 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func fontForUnreadMessage(onSupport genericScaling: Bool = false) -> UIFont? { - - var size: CGFloat = 10 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func font5GMessage(_ genericScaling: Bool) -> UIFont? { - - var size: CGFloat = 16 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func font5GMessage() -> UIFont? { - return font5GMessage(true) - } - - class func font(forHeadlineAlternative genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 24 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func fontForHeadlineAlternative(forWidth size: CGFloat) -> UIFont? { - - var pointSize: CGFloat = 24 - pointSize = Styler.sizeObjectGeneric(forCurrentDevice: pointSize)!.getValueBased(onSize: size) - - return MFFonts.mfFont55Rg(pointSize) - } - - class func fontH255(_ genericScaling: Bool) -> UIFont? { - - var size: CGFloat = 25 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func font(forLargeLoyaltyHeaderTitle genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 60 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func font(forLoyaltyTitleSmall genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 42 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func font(forLoyaltyMessage genericScaling: Bool = true) -> UIFont? { - - var size: CGFloat = 20 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont55Rg(size) - } - - class func font(forPtPCard genericScaling: Bool) -> UIFont? { - - var size: CGFloat = 22 - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func fontForLabelWithTopLeftCircle(withSize size: CGFloat, genericScaling: Bool) -> UIFont? { - - var size = size - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFont75Bd(size) - } - - class func fontOcratxtWitSize(_ size: CGFloat, genericScaling: Bool) -> UIFont? { - - var size = size - - if genericScaling { - size = sizeFontGeneric(forCurrentDevice: size) - } - - return MFFonts.mfFontOcratxt(size) - } - - class func boldFont(forScaledSize size: CGFloat) -> UIFont { - return MFFonts.mfFont75Bd(sizeFontGeneric(forCurrentDevice: size))! - } - - class func regularFont(forScaledSize size: CGFloat) -> UIFont { - return MFFonts.mfFont55Rg(sizeFontGeneric(forCurrentDevice: size))! - } - - //-------------------------------------------------- - // MARK: - 1.0 Attributed Strings Style - //-------------------------------------------------- - - class func styleGetAttributedString(_ string: String?, withStyle style: String?) -> NSAttributedString { - return styleGetAttributedString(string, withStyle: Styler.Style(rawValue: style!)!, genericScaling: true) - } - - class func styleGetAttributedString(_ string: String?, withStyle style: Style, genericScaling: Bool) -> NSAttributedString { - - switch style { - case .H1: - return styleGetH1AttributedString(string, genericScaling: genericScaling) - - case .H2: - return styleGetH2AttributedString(string, genericScaling: genericScaling) - - case .H3: - return styleGetH3AttributedString(string, genericScaling: genericScaling) - - case .H32: - return styleGetH32AttributedString(string, genericScaling: genericScaling) - - case .B1: - return styleGetB1AttributedString(string, genericScaling: genericScaling) - - case .B2: - return styleGetB2AttributedString(string, genericScaling: genericScaling) - - case .B3: - return styleGetB3AttributedString(string, genericScaling: genericScaling) - - case .B20: - return styleGetB20AttributedString(string, genericScaling: genericScaling) - } - } - - class func styleGetAttributedString(_ string: String?, font: UIFont, color: UIColor) -> NSAttributedString { - - var attributedString: NSAttributedString? = nil - - if let string = string, !string.isEmpty { - attributedString = NSAttributedString(string: string, attributes: [NSAttributedString.Key.font: font, - NSAttributedString.Key.foregroundColor: color]) - } else { - attributedString = NSAttributedString(string: "") - } - - return attributedString! - } - - class func styleGetH1AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { - return styleGetAttributedString(string, font: fontH1(genericScaling)!, color: .black) - } - - class func styleGetH2AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { - return styleGetAttributedString(string, font: fontH2(genericScaling)!, color: .black) - } - - class func styleGetH3AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { - return styleGetAttributedString(string, font: fontH3(genericScaling)!, color: .black) - } - - class func styleGetH32AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { - return styleGetAttributedString(string, font: fontH32(genericScaling)!, color: .black) - } - - class func styleGetB1AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { - return styleGetAttributedString(string, font: fontB1(genericScaling)!, color: .black) - } - - class func styleGetB2AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { - return styleGetAttributedString(string, font: fontB2(genericScaling)!, color: .black) - } - - class func styleGetB3AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { - return styleGetAttributedString(string, font: fontB3(genericScaling)!, color: .mfBattleshipGrey()) - } - - class func styleGetB20AttributedString(_ string: String?, genericScaling: Bool = true) -> NSAttributedString { - return styleGetAttributedString(string, font: fontB20(genericScaling)!, color: .black) - } - - class func styleGetTopAlignedAttributeString(withLeftStringRightTop left: String?, center: String, rightString right: String?, withCenterStringFontSize fontSize: CGFloat, andColor color: UIColor) -> NSAttributedString { - - var left = left ?? "" - var center = center - var right = right ?? "" - - let text = "\(left)\(center)\(right)" - let attribs = [NSAttributedString.Key.foregroundColor: color] - var attributedText = NSMutableAttributedString(string: text, attributes: attribs) - - let centerRange = (text as NSString).range(of: center) - let centerFont = MFFonts.mfFont75Bd(fontSize) - let centerHeight = centerFont?.capHeight ?? 0.0 - attributedText.addAttributes([NSAttributedString.Key.font: MFFonts.mfFont75Bd(fontSize) as Any], range: centerRange) - - let leftRange = (text as NSString).range(of: left) - let leftFont = MFFonts.mfFont75Bd(fontSize * 0.34) - let leftHeight = leftFont?.capHeight ?? 0.0 - - if let leftFont = leftFont { - attributedText.addAttributes([NSAttributedString.Key.font: leftFont, - NSAttributedString.Key.baselineOffset: NSNumber(value: Float(centerHeight - leftHeight))], range: leftRange) - } - - let rightRange = NSRange(location: centerRange.location + centerRange.length, length: right.count ) - let rightFont = MFFonts.mfFont75Bd(fontSize * 0.34) - - let offset = Float((centerFont?.pointSize ?? 0.0) - (centerFont?.capHeight ?? 0.0) + (rightFont?.pointSize ?? 0.0) / 2) - - if let rightFont = rightFont { - attributedText.addAttributes([NSAttributedString.Key.font: rightFont, - NSAttributedString.Key.baselineOffset: offset], - range: rightRange) - } - - return attributedText - } - class func styleGetAlignCenteredAttrituedString(_ string: inout NSMutableAttributedString?) { if let string = string, string.length > 0 { let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = .center - string.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: string.length)) + string.addAttribute(.paragraphStyle, + value: paragraphStyle, + range: NSRange(location: 0, length: string.length)) } } @@ -1248,7 +208,9 @@ public class Styler { if openingRange?.location != NSNotFound && closingRange?.location != NSNotFound { let boldLength = (closingRange?.location ?? 0) - (openingRange?.location ?? 0) if let inputFont = inputFont { - attrString.setAttributes([NSAttributedString.Key.font: inputFont], range: NSRange(location: openingRange?.location ?? 0, length: boldLength)) + attrString.setAttributes([NSAttributedString.Key.font: inputFont], + range: NSRange(location: openingRange?.location ?? 0, + length: boldLength)) } if let closingRange = closingRange { @@ -1286,14 +248,14 @@ public class Styler { class func styleGetLowCaseSpace(_ inputString: String?) -> String? { if (inputString?.count ?? 0) > 0 { - let trimmedString = inputString?.lowercased().trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) + let trimmedString = inputString?.lowercased().trimmingCharacters(in: .whitespacesAndNewlines) return trimmedString } return "" } - class func labelStrokeAttributes(_ color: UIColor?) -> [AnyHashable : Any]? { + class func labelStrokeAttributes(_ color: UIColor?) -> [AnyHashable: Any]? { guard let color = color else { return nil } @@ -1301,12 +263,6 @@ public class Styler { NSAttributedString.Key.strokeWidth: -1.0] } - class func mfStyleBlackPageControl(_ pageControl: UIPageControl?) { - - pageControl?.pageIndicatorTintColor = .mfLighterGray() - pageControl?.currentPageIndicatorTintColor = .black - } - //-------------------------------------------------- // MARK: - Custom Styling Views //-------------------------------------------------- @@ -1337,189 +293,8 @@ public class Styler { NSLayoutConstraint.constraintPinSubview(borderLine, pinTop: false, pinBottom: false, pinLeft: false, pinRight: true) NSLayoutConstraint.constraintPinView(borderLine, heightConstraint: true, heightConstant: borderLineLengh, widthConstraint: true, widthConstant: borderLineWidth) NSLayoutConstraint.constraintPinSubview(borderLine, pinCenterX: false, pinCenterY: true) - - default: - break } borderLine.backgroundColor = color } - - class func mfStylePageControl(_ pageControl: UIPageControl?) { - - pageControl?.pageIndicatorTintColor = .mfLighterGray() - pageControl?.currentPageIndicatorTintColor = .mfRed() - } - - class func styleTextField(_ textField: UITextField) { - - textField.font = fontForTextField() - // As per AKQA - /* If the length of the text field exceeds the amount of space, the size of the text drops down. - So, the entire line of copy can be read. - 16 point font size is the lowest recommended size. - */ - textField.minimumFontSize = 16 - textField.adjustsFontSizeToFitWidth = true // default is NO. if YES, text will shrink to minFontSize along baseline - } - /* - class func setGradientTo(_ label: UILabel, withColors colors: [AnyHashable]) { - - var textSize: CGSize? = nil - - if let font = UIFont(name: label.font.fontName, size: label.font.lineHeight) { - textSize = label.text?.size(withAttributes: [NSAttributedString.Key.baselineOffset: 0, - NSAttributedString.Key.font: font]) - } - - let width = (textSize?.width ?? 0.0) > 1024 ? 1024 : textSize?.width ?? 0.0 // max 1024 due to Core Graphics limitations - let height = (textSize?.height ?? 0.0) > 1024 ? 1024 : textSize?.height ?? 0.0 // max 1024 due to Core Graphics limitations - - // create a new bitmap image context - UIGraphicsBeginImageContext(CGSize(width: width, height: height)) - - let context = UIGraphicsGetCurrentContext() - - // push context to make it current (need to do this manually because we are not drawing in a UIView) - if let context = context { - UIGraphicsPushContext(context) - } - - var glossGradient: CGGradient? - var rgbColorspace: CGColorSpace? - let num_locations = colors.count - var locations = [CGFloat](repeating: 0.0, count: colors.count) - let components = [CGFloat](repeating: 0.0, count: colors.count * 4) - var componentIndex = 0 - - for i in 0.. UIImage? { - - UIGraphicsBeginImageContextWithOptions(image?.size ?? CGSize.zero, _: true, _: 1.0) - let imageRect = CGRect(x: 0, y: 0, width: image?.size.width ?? 0.0, height: image?.size.height ?? 0.0) - - // Draw the image with the luminosity blend mode. - // On top of a white background, this will give a black and white image. - image?.draw(in: imageRect, blendMode: .luminosity, alpha: 1.0) - - // Get the resulting image. - let filteredImage = UIGraphicsGetImageFromCurrentImageContext() - UIGraphicsEndImageContext() - - return filteredImage - } - /* - class func getCountTime(_ leftTime: Int, timeformat timeFormat: String?, time timeUnit: MFTimeFormatUnit, timeSuffix suffix: String?) -> String? { - - var seconds = leftTime % 60 - var minutes = (leftTime / 60) % 60 - var hours = (leftTime / 3600) % 24 - let days = leftTime / 86400 - - guard let times = timeFormat?.components(separatedBy: ":") else { return nil } - var timeString = "" - - if times.contains("DD") { - timeString += String(format: "%02ld", days) - - if timeUnit == .mfTimeFormatNormal { - let dayKey = (days <= 1) ? "CountDownDay" : "CountDownDays" - let dayUnit = MVMCoreUIUtility.hardcodedString(withKey: dayKey) - timeString += dayUnit! - - } else if timeUnit == MFTimeFormatColon && times?.last != "DD" { - timeString += " : " - } - - if times.last != "DD" && suffix != nil { - timeString += suffix ?? "" - } - } - - if times.contains("HH") { - if !times.contains("DD") { - hours = leftTime / 3600 - } - - timeString += String(format: "%02d", hours) - - if timeUnit == .mfTimeFormatNormal { - let hourKey = (hours <= 1) ? "CountDownHour" : "CountDownHours" - let hourUnit = MVMCoreUIUtility.hardcodedString(withKey: hourKey)! - timeString += hourUnit - - } else if timeUnit == MFTimeFormatColon && times?.last != "HH" { - timeString += " : " - } - - if times.last != "HH" && suffix != nil { - timeString += suffix ?? "" - } - } - - if times.contains("MM") { - if !times.contains("HH") { - if !times.contains("DD") { - minutes = leftTime / 60 - } else { - minutes = (leftTime - days * 86400) / 60 - } - } - - timeString += String(format: "%02d", minutes) - - if times.contains("SS") { - if !times.contains("MM") { - if !times.contains("HH") { - if !times.contains("DD") { - seconds = leftTime - } else { - seconds = leftTime % 86400 - } - } else { - seconds = leftTime % 3600 - } - } - - timeString += String(format: "%02d", seconds) - - if timeUnit == .mfTimeFormatNormal { - let secondKey = (seconds <= 1) ? "CountDownSec" : "CountDownSecs" - let secondUnit = MVMCoreUIUtility.hardcodedString(withKey: secondKey) - timeString += secondUnit! - } - } - return timeString - } - } - */ } From 1758192edfbe87bb4a71937f42cfa28cb10988f6 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 1 Apr 2020 17:03:03 -0400 Subject: [PATCH 04/31] decent state --- MVMCoreUI.xcodeproj/project.pbxproj | 4 + MVMCoreUI/Styles/Styler.swift | 182 ++------------------------- MVMCoreUI/Styles/VogueProtocol.swift | 23 ++++ 3 files changed, 39 insertions(+), 170 deletions(-) create mode 100644 MVMCoreUI/Styles/VogueProtocol.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index ddb3307c..101d0c8d 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -89,6 +89,7 @@ 0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */; }; 0A6682AA2435125F00AD3CA1 /* Styler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682A92435125F00AD3CA1 /* Styler.swift */; }; 0A6682AC243531C300AD3CA1 /* Padding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682AB243531C300AD3CA1 /* Padding.swift */; }; + 0A6682AE243538DB00AD3CA1 /* VogueProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682AD243538DB00AD3CA1 /* VogueProtocol.swift */; }; 0A69F611241BDEA700F7231B /* RuleAnyRequiredModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */; }; 0A6BF4722360C56C0028F841 /* BaseDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */; }; 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; }; @@ -476,6 +477,7 @@ 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleGuidelinesProtocol.swift; sourceTree = ""; }; 0A6682A92435125F00AD3CA1 /* Styler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Styler.swift; sourceTree = ""; }; 0A6682AB243531C300AD3CA1 /* Padding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Padding.swift; sourceTree = ""; }; + 0A6682AD243538DB00AD3CA1 /* VogueProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VogueProtocol.swift; sourceTree = ""; }; 0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleAnyRequiredModel.swift; sourceTree = ""; }; 0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseDropdownEntryField.swift; sourceTree = ""; }; 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyButton.swift; sourceTree = ""; }; @@ -1472,6 +1474,7 @@ D29DF13921E68637003B2FB9 /* MFStyler.m */, 0A6682A92435125F00AD3CA1 /* Styler.swift */, 0A6682AB243531C300AD3CA1 /* Padding.swift */, + 0A6682AD243538DB00AD3CA1 /* VogueProtocol.swift */, ); path = Styles; sourceTree = ""; @@ -2005,6 +2008,7 @@ AA11A42123F15D7000D7962F /* ListRightVariablePaymentsModel.swift in Sources */, 01EB369223609801006832FA /* MoleculeStackModel.swift in Sources */, 011D9626240EBB16000E3791 /* RadioButtonLabelModel.swift in Sources */, + 0A6682AE243538DB00AD3CA1 /* VogueProtocol.swift in Sources */, AAA74A192410C05800080241 /* HeadersH2NoButtonsBodyTextModel.swift in Sources */, D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */, 944589232385DA9600DE9FD4 /* ImageViewModel.swift in Sources */, diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index a43bc47a..62af40fe 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -7,39 +7,14 @@ // import Foundation -import MVMCore - - -public protocol VogueProtocol { - -} - -public protocol VogueViewProtocol { - -} - -public protocol VogueTextProtocol: VogueProtocol { - func styleFont(_ font: UIFont) - func styleTextColor(_ textColor: UIColor) -} - - open class Styler { - //-------------------------------------------------- // MARK: - Enums //-------------------------------------------------- - enum MFViewBorder: Int { - case top - case left - case bottom - case right - } - - public enum FontStyle: String { + public enum Font: String { case Title2XLarge case TitleXLarge case BoldTitleLarge @@ -53,7 +28,7 @@ open class Styler { case BoldMicro case RegularMicro - func pointSize() -> CGFloat { + public func pointSize() -> CGFloat { switch self { case .Title2XLarge: return 36 @@ -82,7 +57,7 @@ open class Styler { } } - func isBold() -> Bool { + public func isBold() -> Bool { switch self { case .Title2XLarge, @@ -103,39 +78,24 @@ open class Styler { } } - func getFont(_ genericScaling: Bool = true) -> UIFont? { + public func getFont(_ genericScaling: Bool = true) -> UIFont? { let size = genericScaling ? sizeFontGeneric(forCurrentDevice: pointSize()) : pointSize() return getMVA3FontSize(size, bold: isBold()) } - func styleLabel(_ label: UILabel, genericScaling: Bool = true) { + public func styleLabel(_ label: UILabel, genericScaling: Bool = true) { label.font = getFont(genericScaling) label.textColor = .black } } - - public enum Tier { - case primary - case secondary - case ternary - case quaternary - } - + //-------------------------------------------------- // MARK: - Functions //-------------------------------------------------- - class func splitTextFieldWidth() -> CGFloat { - return splitTextFieldWidth(forViewWidth: MVMCoreUISplitViewController.getDetailViewWidth()) - } - - class func splitTextFieldWidth(forViewWidth width: CGFloat) -> CGFloat { - return (width - CGFloat(PaddingOne)) / 2 - Padding.Default.HorizontalPaddingForApplicationWidth - } - - class func sizeObjectGeneric(forCurrentDevice size: CGFloat) -> MFSizeObject? { + open class func sizeObjectGeneric(forCurrentDevice size: CGFloat) -> MFSizeObject? { let sizeObject = MFSizeObject(standardSize: size, standardiPadPortraitSize: size * 1.3) sizeObject?.addLargerThanCustomSize(size * 1.4, forThreshold: MFSizeStandardiPadLandscapeThreshold) @@ -143,7 +103,7 @@ open class Styler { return sizeObject } - class func sizeFontGeneric(forCurrentDevice size: CGFloat) -> CGFloat { + open class func sizeFontGeneric(forCurrentDevice size: CGFloat) -> CGFloat { return sizeObjectGeneric(forCurrentDevice: size)?.getValueBasedOnApplicationWidth() ?? 0 } @@ -151,7 +111,7 @@ open class Styler { // MARK: - Spacing //-------------------------------------------------- - class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat, horizontal: Bool = true, vertical: Bool = false) { + open class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat, horizontal: Bool = true, vertical: Bool = false) { let horizontalPadding: CGFloat = horizontal ? Padding.Default.horizontalPadding(forSize: size) : 0 let verticalPadding: CGFloat = vertical ? PaddingDefaultVerticalSpacing3 : 0 @@ -161,7 +121,7 @@ open class Styler { } } - class func setMarginsFor(_ view: UIView?, size: CGFloat, defaultHorizontal horizontal: Bool, top: CGFloat, bottom: CGFloat) { + open class func setMarginsFor(_ view: UIView?, size: CGFloat, defaultHorizontal horizontal: Bool, top: CGFloat, bottom: CGFloat) { let horizontalPadding: CGFloat = horizontal ? Padding.Default.horizontalPadding(forSize: size) : 0 @@ -169,12 +129,8 @@ open class Styler { MVMCoreUIUtility.setMarginsFor(view, leading: horizontalPadding, top: top, trailing: horizontalPadding, bottom: bottom) } } - - //-------------------------------------------------- - // MARK: - 3.0 fonts - //-------------------------------------------------- - - class func getMVA3FontSize(_ size: CGFloat, bold isBold: Bool) -> UIFont { + + open class func getMVA3FontSize(_ size: CGFloat, bold isBold: Bool) -> UIFont { if isBold { return size >= 15 ? MFFonts.mfFontDSBold(size) : MFFonts.mfFontTXBold(size) @@ -183,118 +139,4 @@ open class Styler { return size >= 15 ? MFFonts.mfFontDSRegular(size) : MFFonts.mfFontTXRegular(size) } } - - //-------------------------------------------------- - // MARK: - Styles - //-------------------------------------------------- - - class func styleGetAlignCenteredAttrituedString(_ string: inout NSMutableAttributedString?) { - - if let string = string, string.length > 0 { - let paragraphStyle = NSMutableParagraphStyle() - paragraphStyle.alignment = .center - string.addAttribute(.paragraphStyle, - value: paragraphStyle, - range: NSRange(location: 0, length: string.length)) - } - } - - class func styleGetBoldString(with inputFont: UIFont?, from inputString: String?) -> NSAttributedString? { - - let openingRange = (inputString as NSString?)?.range(of: "{") - let closingRange = (inputString as NSString?)?.range(of: "}") - let attrString = NSMutableAttributedString(string: inputString ?? "") - - if openingRange?.location != NSNotFound && closingRange?.location != NSNotFound { - let boldLength = (closingRange?.location ?? 0) - (openingRange?.location ?? 0) - if let inputFont = inputFont { - attrString.setAttributes([NSAttributedString.Key.font: inputFont], - range: NSRange(location: openingRange?.location ?? 0, - length: boldLength)) - } - - if let closingRange = closingRange { - attrString.replaceCharacters(in: closingRange, with: "") - } - - if let openingRange = openingRange { - attrString.replaceCharacters(in: openingRange, with: "") - } - } - - return attrString - } - - //-------------------------------------------------- - // MARK: - Gradient Colors - //-------------------------------------------------- - - class func gradientSpecialTicketGold() -> [AnyHashable] { - return [UIColor(red: 0.72, green: 0.6, blue: 0.33, alpha: 1), - UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1), - UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1), - UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1), - UIColor(red: 0.6, green: 0.42, blue: 0.07, alpha: 1)] - } - - class func gradientSpecialTicketGoldCGColor() -> [AnyHashable] { - return [UIColor(red: 0.72, green: 0.6, blue: 0.33, alpha: 1).cgColor, - UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1).cgColor, - UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1).cgColor, - UIColor(red: 1, green: 0.85, blue: 0.52, alpha: 1).cgColor, - UIColor(red: 0.6, green: 0.42, blue: 0.07, alpha: 1).cgColor].compactMap { $0 } - } - - class func styleGetLowCaseSpace(_ inputString: String?) -> String? { - - if (inputString?.count ?? 0) > 0 { - let trimmedString = inputString?.lowercased().trimmingCharacters(in: .whitespacesAndNewlines) - return trimmedString - } - - return "" - } - - class func labelStrokeAttributes(_ color: UIColor?) -> [AnyHashable: Any]? { - - guard let color = color else { return nil } - - return [NSAttributedString.Key.strokeColor: color, - NSAttributedString.Key.strokeWidth: -1.0] - } - - //-------------------------------------------------- - // MARK: - Custom Styling Views - //-------------------------------------------------- - - class func styleView(_ view: UIView, show border: MFViewBorder, with color: UIColor?, borderLineWidth: CGFloat, borderLineLength borderLineLengh: CGFloat) { - - let borderLine = UIView(frame: .zero) - borderLine.translatesAutoresizingMaskIntoConstraints = false - view.addSubview(borderLine) - - switch border { - case .top: - NSLayoutConstraint.constraintPinSubview(borderLine, pinTop: true, pinBottom: false, pinLeft: false, pinRight: false) - NSLayoutConstraint.constraintPinView(borderLine, heightConstraint: true, heightConstant: borderLineWidth, widthConstraint: true, widthConstant: borderLineLengh) - NSLayoutConstraint.constraintPinSubview(borderLine, pinCenterX: true, pinCenterY: false) - - case .left: - NSLayoutConstraint.constraintPinSubview(borderLine, pinTop: false, pinBottom: false, pinLeft: true, pinRight: false) - NSLayoutConstraint.constraintPinView(borderLine, heightConstraint: true, heightConstant: borderLineLengh, widthConstraint: true, widthConstant: borderLineWidth) - NSLayoutConstraint.constraintPinSubview(borderLine, pinCenterX: false, pinCenterY: true) - - case .bottom: - NSLayoutConstraint.constraintPinSubview(borderLine, pinTop: false, pinBottom: true, pinLeft: false, pinRight: false) - NSLayoutConstraint.constraintPinView(borderLine, heightConstraint: true, heightConstant: borderLineWidth, widthConstraint: true, widthConstant: borderLineLengh) - NSLayoutConstraint.constraintPinSubview(borderLine, pinCenterX: true, pinCenterY: false) - - case .right: - NSLayoutConstraint.constraintPinSubview(borderLine, pinTop: false, pinBottom: false, pinLeft: false, pinRight: true) - NSLayoutConstraint.constraintPinView(borderLine, heightConstraint: true, heightConstant: borderLineLengh, widthConstraint: true, widthConstant: borderLineWidth) - NSLayoutConstraint.constraintPinSubview(borderLine, pinCenterX: false, pinCenterY: true) - } - - borderLine.backgroundColor = color - } } diff --git a/MVMCoreUI/Styles/VogueProtocol.swift b/MVMCoreUI/Styles/VogueProtocol.swift new file mode 100644 index 00000000..1bd8e6a8 --- /dev/null +++ b/MVMCoreUI/Styles/VogueProtocol.swift @@ -0,0 +1,23 @@ +// +// VogueProtocol.swift +// MVMCoreUI +// +// Created by Kevin Christiano on 4/1/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + + +public protocol VogueProtocol { + +} + +public protocol VogueViewProtocol { + +} + +public protocol VogueTextProtocol: VogueProtocol { + func styleFont(_ font: UIFont) + func styleTextColor(_ textColor: UIColor) +} From c26eea8cddd13666efad0cb8eaca40a94c0a9baf Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 1 Apr 2020 17:12:26 -0400 Subject: [PATCH 05/31] small change --- MVMCoreUI/Styles/Styler.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 62af40fe..75d81b89 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -81,7 +81,7 @@ open class Styler { public func getFont(_ genericScaling: Bool = true) -> UIFont? { let size = genericScaling ? sizeFontGeneric(forCurrentDevice: pointSize()) : pointSize() - return getMVA3FontSize(size, bold: isBold()) + return getMVA3FontSize(size, isBold: isBold()) } public func styleLabel(_ label: UILabel, genericScaling: Bool = true) { @@ -130,7 +130,7 @@ open class Styler { } } - open class func getMVA3FontSize(_ size: CGFloat, bold isBold: Bool) -> UIFont { + open class func getMVA3FontSize(_ size: CGFloat, isBold: Bool) -> UIFont { if isBold { return size >= 15 ? MFFonts.mfFontDSBold(size) : MFFonts.mfFontTXBold(size) From 8788d98323186ac52a025bbaafb058ddb5e4a21f Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 2 Apr 2020 11:20:17 -0400 Subject: [PATCH 06/31] updates --- MVMCoreUI/Styles/Padding.swift | 5 +---- MVMCoreUI/Styles/Styler.swift | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Styles/Padding.swift b/MVMCoreUI/Styles/Padding.swift index bdd65837..b47a64c5 100644 --- a/MVMCoreUI/Styles/Padding.swift +++ b/MVMCoreUI/Styles/Padding.swift @@ -24,7 +24,6 @@ public struct Padding { public static let TableCellParagraphSpace: CGFloat = 3 public static let FooterLabelParagraphSpace: CGFloat = 4 - public static let WebViewInset: CGFloat = 8 public static let HeightTableSeperatorHeight: CGFloat = 1 public static let MFHeightForSwitch: CGFloat = 22 public static let MFWidthForSwitch: CGFloat = 42 @@ -33,9 +32,7 @@ public struct Padding { public static let MinCellHeight: CGFloat = 96 public static let HeightIphone5: CGFloat = 568 public static let DefaultOptionCellHeight: CGFloat = 120 - public static let PromoViewHeight: CGFloat = 41.9 public static let BetweenFields: CGFloat = 24 - public static let LabelWithInternalButtonLineSpace: CGFloat = 2 public static let PrimaryButtonTop: CGFloat = 36 public struct Default { @@ -45,7 +42,7 @@ public struct Padding { public static let VerticalSpacing3: CGFloat = 24 public static var HorizontalPaddingForApplicationWidth: CGFloat { - return MFSizeObject(scalingStandardSize: PaddingDefaultHorizontalSpacing)?.getValueBasedOnApplicationWidth() ?? 0 + return MFSizeObject(scalingStandardSize: PaddingDefaultHorizontalSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalSpacing } public static var VerticalPaddingForApplicationWidth: CGFloat { diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 75d81b89..46210b9c 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -104,7 +104,7 @@ open class Styler { } open class func sizeFontGeneric(forCurrentDevice size: CGFloat) -> CGFloat { - return sizeObjectGeneric(forCurrentDevice: size)?.getValueBasedOnApplicationWidth() ?? 0 + return sizeObjectGeneric(forCurrentDevice: size)?.getValueBasedOnApplicationWidth() ?? size } //-------------------------------------------------- From c9bb3ce1f389553ae05be14af7b42cf1c4aeac1b Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 2 Apr 2020 17:16:04 -0400 Subject: [PATCH 07/31] including 2.0 legacy as it's being used in some molecular at the moment. --- .../Views/Label/LabelAttributeFontModel.swift | 4 +- .../Atomic/Atoms/Views/Label/LabelModel.swift | 29 +---- MVMCoreUI/Styles/Styler.swift | 104 +++++++++++++++--- 3 files changed, 90 insertions(+), 47 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeFontModel.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeFontModel.swift index 437bb6f8..862f8f9b 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeFontModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelAttributeFontModel.swift @@ -18,7 +18,7 @@ import UIKit return "font" } - var style: LabelModel.FontStyle? + var style: Styler.Font? var name: String? var size: CGFloat? @@ -38,7 +38,7 @@ import UIKit required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - style = try typeContainer.decodeIfPresent(LabelModel.FontStyle.self, forKey: .style) + style = try typeContainer.decodeIfPresent(Styler.Font.self, forKey: .style) name = try typeContainer.decodeIfPresent(String.self, forKey: .name) size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size) try super.init(from: decoder) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift index 74e6efa4..4ec23ad6 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/LabelModel.swift @@ -10,31 +10,6 @@ import Foundation @objcMembers public class LabelModel: MoleculeModelProtocol { - - public enum FontStyle: String, Codable { - case Title2XLarge - case TitleXLarge - case BoldTitleLarge - case RegularTitleLarge - case BoldTitleMedium - case RegularTitleMedium - case BoldBodyLarge - case RegularBodyLarge - case BoldBodySmall - case RegularBodySmall - case BoldMicro - case RegularMicro - // Legacy - case H1 - case H2 - case H3 - case H32 - case B1 - case B2 - case B3 - case B20 - } - //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- @@ -44,7 +19,7 @@ import Foundation public var text: String public var accessibilityText: String? public var textColor: Color? - public var fontStyle: FontStyle? + public var fontStyle: Styler.Font? public var fontName: String? public var fontSize: CGFloat? public var textAlignment: NSTextAlignment? @@ -95,7 +70,7 @@ import Foundation accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) textColor = try typeContainer.decodeIfPresent(Color.self, forKey: .textColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - fontStyle = try typeContainer.decodeIfPresent(FontStyle.self, forKey: .fontStyle) + fontStyle = try typeContainer.decodeIfPresent(Styler.Font.self, forKey: .fontStyle) fontName = try typeContainer.decodeIfPresent(String.self, forKey: .fontName) fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .fontSize) textAlignment = try typeContainer.decodeIfPresent(NSTextAlignment.self, forKey: .textAlignment) diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 46210b9c..57b0ad18 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -14,7 +14,7 @@ open class Styler { // MARK: - Enums //-------------------------------------------------- - public enum Font: String { + public enum Font: String, Codable { case Title2XLarge case TitleXLarge case BoldTitleLarge @@ -28,31 +28,56 @@ open class Styler { case BoldMicro case RegularMicro + // Legacy Fonts + case H1 + case H2 + case H3 + case H32 + case B1 + case B2 + case B3 + case B20 + public func pointSize() -> CGFloat { switch self { + case .H1: + return 40 + case .Title2XLarge: return 36 - case .TitleXLarge: + case .TitleXLarge, + .H32: return 32 + case .H2: + return 25 + case .BoldTitleLarge, .RegularTitleLarge: return 24 case .BoldTitleMedium, - .RegularTitleMedium: + .RegularTitleMedium, + .B20: return 20 + case .H3: + return 18 + case .BoldBodyLarge, .RegularBodyLarge: return 16 case .BoldBodySmall, - .RegularBodySmall: + .RegularBodySmall, + .B1, + .B2: return 13 - case .BoldMicro, .RegularMicro: + case .BoldMicro, + .RegularMicro, + .B3: return 11 } } @@ -66,14 +91,51 @@ open class Styler { .RegularTitleMedium, .RegularBodyLarge, .RegularBodySmall, - .RegularMicro: + .RegularMicro, + .B2, + .B3, + .B20: return false case .BoldTitleLarge, + .BoldTitleMedium, + .BoldBodyLarge, + .BoldBodySmall, + .BoldMicro, + .H1, + .H2, + .H3, + .H32, + .B1: + return true + } + } + + public func isLegacyFont() -> Bool { + + switch self { + case .Title2XLarge, + .TitleXLarge, + .RegularTitleLarge, + .RegularTitleMedium, + .RegularBodyLarge, + .RegularBodySmall, + .RegularMicro, + .BoldTitleLarge, .BoldTitleMedium, .BoldBodyLarge, .BoldBodySmall, .BoldMicro: + return false + + case .H1, + .H2, + .H3, + .H32, + .B1, + .B2, + .B3, + .B20: return true } } @@ -81,7 +143,23 @@ open class Styler { public func getFont(_ genericScaling: Bool = true) -> UIFont? { let size = genericScaling ? sizeFontGeneric(forCurrentDevice: pointSize()) : pointSize() - return getMVA3FontSize(size, isBold: isBold()) + + if isLegacyFont() { + switch self { + case .B2, .B3, .B20: + return MFFonts.mfFont55Rg(size) + + default: + return MFFonts.mfFont75Bd(size) + } + } else { + if isBold() { + return size >= 15 ? MFFonts.mfFontDSBold(size) : MFFonts.mfFontTXBold(size) + + } else { + return size >= 15 ? MFFonts.mfFontDSRegular(size) : MFFonts.mfFontTXRegular(size) + } + } } public func styleLabel(_ label: UILabel, genericScaling: Bool = true) { @@ -90,7 +168,7 @@ open class Styler { label.textColor = .black } } - + //-------------------------------------------------- // MARK: - Functions //-------------------------------------------------- @@ -129,14 +207,4 @@ open class Styler { MVMCoreUIUtility.setMarginsFor(view, leading: horizontalPadding, top: top, trailing: horizontalPadding, bottom: bottom) } } - - open class func getMVA3FontSize(_ size: CGFloat, isBold: Bool) -> UIFont { - - if isBold { - return size >= 15 ? MFFonts.mfFontDSBold(size) : MFFonts.mfFontTXBold(size) - - } else { - return size >= 15 ? MFFonts.mfFontDSRegular(size) : MFFonts.mfFontTXRegular(size) - } - } } From de6fe50c82776cef7d13c0ec3e922730d1349de8 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 3 Apr 2020 11:19:51 -0400 Subject: [PATCH 08/31] updates --- MVMCoreUI.xcodeproj/project.pbxproj | 12 +++------ MVMCoreUI/Styles/Padding.swift | 37 +++++----------------------- MVMCoreUI/Styles/Styler.swift | 17 ++++++++++--- MVMCoreUI/Styles/VogueProtocol.swift | 23 ----------------- 4 files changed, 23 insertions(+), 66 deletions(-) delete mode 100644 MVMCoreUI/Styles/VogueProtocol.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 2679f3f0..f7bdfec3 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -85,11 +85,10 @@ 0A41BA6E2344FCD400D4C0BC /* CATransaction+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */; }; 0A41BA7F23453A6400D4C0BC /* TextEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A41BA7E23453A6400D4C0BC /* TextEntryField.swift */; }; 0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */; }; - 0A6682AA2435125F00AD3CA1 /* Styler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682A92435125F00AD3CA1 /* Styler.swift */; }; - 0A6682AC243531C300AD3CA1 /* Padding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682AB243531C300AD3CA1 /* Padding.swift */; }; - 0A6682AE243538DB00AD3CA1 /* VogueProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682AD243538DB00AD3CA1 /* VogueProtocol.swift */; }; 0A6682A22434DB4F00AD3CA1 /* ListLeftVariableRadioButtonBodyText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682A12434DB4F00AD3CA1 /* ListLeftVariableRadioButtonBodyText.swift */; }; 0A6682A42434DB8D00AD3CA1 /* ListLeftVariableRadioButtonBodyTextModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682A32434DB8D00AD3CA1 /* ListLeftVariableRadioButtonBodyTextModel.swift */; }; + 0A6682AA2435125F00AD3CA1 /* Styler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682A92435125F00AD3CA1 /* Styler.swift */; }; + 0A6682AC243531C300AD3CA1 /* Padding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6682AB243531C300AD3CA1 /* Padding.swift */; }; 0A69F611241BDEA700F7231B /* RuleAnyRequiredModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */; }; 0A6BF4722360C56C0028F841 /* BaseDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */; }; 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; }; @@ -479,11 +478,10 @@ 0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CATransaction+Extension.swift"; sourceTree = ""; }; 0A41BA7E23453A6400D4C0BC /* TextEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextEntryField.swift; sourceTree = ""; }; 0A5D59C123AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleGuidelinesProtocol.swift; sourceTree = ""; }; - 0A6682A92435125F00AD3CA1 /* Styler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Styler.swift; sourceTree = ""; }; - 0A6682AB243531C300AD3CA1 /* Padding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Padding.swift; sourceTree = ""; }; - 0A6682AD243538DB00AD3CA1 /* VogueProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VogueProtocol.swift; sourceTree = ""; }; 0A6682A12434DB4F00AD3CA1 /* ListLeftVariableRadioButtonBodyText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableRadioButtonBodyText.swift; sourceTree = ""; }; 0A6682A32434DB8D00AD3CA1 /* ListLeftVariableRadioButtonBodyTextModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableRadioButtonBodyTextModel.swift; sourceTree = ""; }; + 0A6682A92435125F00AD3CA1 /* Styler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Styler.swift; sourceTree = ""; }; + 0A6682AB243531C300AD3CA1 /* Padding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Padding.swift; sourceTree = ""; }; 0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleAnyRequiredModel.swift; sourceTree = ""; }; 0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseDropdownEntryField.swift; sourceTree = ""; }; 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyButton.swift; sourceTree = ""; }; @@ -1490,7 +1488,6 @@ D29DF13921E68637003B2FB9 /* MFStyler.m */, 0A6682A92435125F00AD3CA1 /* Styler.swift */, 0A6682AB243531C300AD3CA1 /* Padding.swift */, - 0A6682AD243538DB00AD3CA1 /* VogueProtocol.swift */, ); path = Styles; sourceTree = ""; @@ -2029,7 +2026,6 @@ AA11A42123F15D7000D7962F /* ListRightVariablePaymentsModel.swift in Sources */, 01EB369223609801006832FA /* MoleculeStackModel.swift in Sources */, 011D9626240EBB16000E3791 /* RadioButtonLabelModel.swift in Sources */, - 0A6682AE243538DB00AD3CA1 /* VogueProtocol.swift in Sources */, AAA74A192410C05800080241 /* HeadersH2NoButtonsBodyTextModel.swift in Sources */, D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */, 944589232385DA9600DE9FD4 /* ImageViewModel.swift in Sources */, diff --git a/MVMCoreUI/Styles/Padding.swift b/MVMCoreUI/Styles/Padding.swift index b47a64c5..1c3bba53 100644 --- a/MVMCoreUI/Styles/Padding.swift +++ b/MVMCoreUI/Styles/Padding.swift @@ -22,50 +22,25 @@ public struct Padding { public static let Nine: CGFloat = 54 public static let Ten: CGFloat = 60 - public static let TableCellParagraphSpace: CGFloat = 3 - public static let FooterLabelParagraphSpace: CGFloat = 4 - public static let HeightTableSeperatorHeight: CGFloat = 1 - public static let MFHeightForSwitch: CGFloat = 22 - public static let MFWidthForSwitch: CGFloat = 42 - public static let DisableOppacity: CGFloat = 0.5 - public static let PaymentMethodViewHeightWidthMultiplier: CGFloat = 0.55 - public static let MinCellHeight: CGFloat = 96 - public static let HeightIphone5: CGFloat = 568 - public static let DefaultOptionCellHeight: CGFloat = 120 - public static let BetweenFields: CGFloat = 24 - public static let PrimaryButtonTop: CGFloat = 36 - public struct Default { public static let Standard: CGFloat = 24 public static let HorizontalSpacing: CGFloat = 32 public static let VerticalSpacing: CGFloat = 32 - public static let VerticalSpacing3: CGFloat = 24 public static var HorizontalPaddingForApplicationWidth: CGFloat { - return MFSizeObject(scalingStandardSize: PaddingDefaultHorizontalSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalSpacing + return MFSizeObject(scalingStandardSize: HorizontalSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalSpacing } public static var VerticalPaddingForApplicationWidth: CGFloat { - return MFSizeObject(scalingStandardSize: PaddingDefaultVerticalSpacing)?.getValueBasedOnApplicationWidth() ?? 0 + return MFSizeObject(scalingStandardSize: VerticalSpacing)?.getValueBasedOnApplicationWidth() ?? VerticalSpacing } - public static func horizontalPadding(forSize size: CGFloat) -> CGFloat { - return MFSizeObject(scalingStandardSize: PaddingDefaultHorizontalSpacing)?.getValueBased(onSize: size) ?? 0 + public static func horizontalPaddingForSize(_ size: CGFloat) -> CGFloat { + return MFSizeObject(scalingStandardSize: HorizontalSpacing)?.getValueBased(onSize: size) ?? VerticalSpacing } - public static func verticalPadding(forSize size: CGFloat) -> CGFloat { - return MFSizeObject(scalingStandardSize: PaddingDefaultVerticalSpacing)?.getValueBased(onSize: size) ?? 0 + public static func verticalPaddingForSize(_ size: CGFloat) -> CGFloat { + return MFSizeObject(scalingStandardSize: VerticalSpacing)?.getValueBased(onSize: size) ?? VerticalSpacing } } - - public struct Horizontal { - public static let HeadlineWhiteView: CGFloat = 60 - public static let Large: CGFloat = 72 - public static let BetweenRelatedItems: CGFloat = 16 - } - - public struct Vertical { - public static let WhiteGrayView: CGFloat = 72 - public static let HeadlineAlternate: CGFloat = 48 - } } diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 57b0ad18..06a4b41f 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -178,6 +178,7 @@ open class Styler { let sizeObject = MFSizeObject(standardSize: size, standardiPadPortraitSize: size * 1.3) sizeObject?.addLargerThanCustomSize(size * 1.4, forThreshold: MFSizeStandardiPadLandscapeThreshold) sizeObject?.addLargerThanCustomSize(size * 1.5, forThreshold: MFSizeiPadProLandscapeThreshold) + return sizeObject } @@ -191,20 +192,28 @@ open class Styler { open class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat, horizontal: Bool = true, vertical: Bool = false) { - let horizontalPadding: CGFloat = horizontal ? Padding.Default.horizontalPadding(forSize: size) : 0 + let horizontalPadding: CGFloat = horizontal ? Padding.Default.horizontalPaddingForSize(size) : 0 let verticalPadding: CGFloat = vertical ? PaddingDefaultVerticalSpacing3 : 0 DispatchQueue.main.async { - MVMCoreUIUtility.setMarginsFor(view, leading: horizontalPadding, top: verticalPadding, trailing: horizontalPadding, bottom: verticalPadding) + MVMCoreUIUtility.setMarginsFor(view, + leading: horizontalPadding, + top: verticalPadding, + trailing: horizontalPadding, + bottom: verticalPadding) } } open class func setMarginsFor(_ view: UIView?, size: CGFloat, defaultHorizontal horizontal: Bool, top: CGFloat, bottom: CGFloat) { - let horizontalPadding: CGFloat = horizontal ? Padding.Default.horizontalPadding(forSize: size) : 0 + let horizontalPadding: CGFloat = horizontal ? Padding.Default.horizontalPaddingForSize(size) : 0 DispatchQueue.main.async { - MVMCoreUIUtility.setMarginsFor(view, leading: horizontalPadding, top: top, trailing: horizontalPadding, bottom: bottom) + MVMCoreUIUtility.setMarginsFor(view, + leading: horizontalPadding, + top: top, + trailing: horizontalPadding, + bottom: bottom) } } } diff --git a/MVMCoreUI/Styles/VogueProtocol.swift b/MVMCoreUI/Styles/VogueProtocol.swift deleted file mode 100644 index 1bd8e6a8..00000000 --- a/MVMCoreUI/Styles/VogueProtocol.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// VogueProtocol.swift -// MVMCoreUI -// -// Created by Kevin Christiano on 4/1/20. -// Copyright © 2020 Verizon Wireless. All rights reserved. -// - -import Foundation - - -public protocol VogueProtocol { - -} - -public protocol VogueViewProtocol { - -} - -public protocol VogueTextProtocol: VogueProtocol { - func styleFont(_ font: UIFont) - func styleTextColor(_ textColor: UIColor) -} From c0d85694c68269980e578917edcfdeeac048a26f Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 3 Apr 2020 11:25:29 -0400 Subject: [PATCH 09/31] more updates --- MVMCoreUI/Styles/Styler.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 06a4b41f..24a1d94c 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -162,6 +162,7 @@ open class Styler { } } + /// Styles the provided label to the declared enum Font case. public func styleLabel(_ label: UILabel, genericScaling: Bool = true) { label.font = getFont(genericScaling) From cf6db73acbdf05cfa45789725c1f3e6a60cd2d22 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 3 Apr 2020 11:28:05 -0400 Subject: [PATCH 10/31] comments --- MVMCoreUI/Styles/Styler.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 24a1d94c..2815873b 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -38,6 +38,7 @@ open class Styler { case B3 case B20 + /// Returns the font size of the current enum case. public func pointSize() -> CGFloat { switch self { case .H1: @@ -82,6 +83,7 @@ open class Styler { } } + /// Determines if the selected font case is bold or regular. public func isBold() -> Bool { switch self { @@ -111,6 +113,7 @@ open class Styler { } } + /// Determines if the current enum is a legacy or modern font. public func isLegacyFont() -> Bool { switch self { @@ -140,6 +143,7 @@ open class Styler { } } + /// Returns the font based on the declared enum case. public func getFont(_ genericScaling: Bool = true) -> UIFont? { let size = genericScaling ? sizeFontGeneric(forCurrentDevice: pointSize()) : pointSize() From 1331c34579ccb8ce23425b3ad22d5c6cb2fca7e5 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 3 Apr 2020 13:10:14 -0400 Subject: [PATCH 11/31] changes made --- MVMCoreUI/Styles/Padding.swift | 3 ++- MVMCoreUI/Styles/Styler.swift | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Styles/Padding.swift b/MVMCoreUI/Styles/Padding.swift index 1c3bba53..6ef0cc62 100644 --- a/MVMCoreUI/Styles/Padding.swift +++ b/MVMCoreUI/Styles/Padding.swift @@ -26,6 +26,7 @@ public struct Padding { public static let Standard: CGFloat = 24 public static let HorizontalSpacing: CGFloat = 32 public static let VerticalSpacing: CGFloat = 32 + public static let VerticalSpacing3: CGFloat = 24 public static var HorizontalPaddingForApplicationWidth: CGFloat { return MFSizeObject(scalingStandardSize: HorizontalSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalSpacing @@ -36,7 +37,7 @@ public struct Padding { } public static func horizontalPaddingForSize(_ size: CGFloat) -> CGFloat { - return MFSizeObject(scalingStandardSize: HorizontalSpacing)?.getValueBased(onSize: size) ?? VerticalSpacing + return MFSizeObject(scalingStandardSize: HorizontalSpacing)?.getValueBased(onSize: size) ?? HorizontalSpacing } public static func verticalPaddingForSize(_ size: CGFloat) -> CGFloat { diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 2815873b..75d0b9ee 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -195,10 +195,14 @@ open class Styler { // MARK: - Spacing //-------------------------------------------------- - open class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat, horizontal: Bool = true, vertical: Bool = false) { + open class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat?, horizontal: Bool = true, vertical: Bool = false) { - let horizontalPadding: CGFloat = horizontal ? Padding.Default.horizontalPaddingForSize(size) : 0 - let verticalPadding: CGFloat = vertical ? PaddingDefaultVerticalSpacing3 : 0 + var horizontalPadding: CGFloat = Padding.Default.HorizontalSpacing + let verticalPadding: CGFloat = vertical ? Padding.Default.VerticalSpacing3 : 0 + + if let size = size { + horizontalPadding = horizontal ? Padding.Default.horizontalPaddingForSize(size) : 0 + } DispatchQueue.main.async { MVMCoreUIUtility.setMarginsFor(view, From e4f561ca7d0aca90d99d96081d31e7e607b439cf Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 3 Apr 2020 13:16:50 -0400 Subject: [PATCH 12/31] lowercasd --- MVMCoreUI/Styles/Padding.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Styles/Padding.swift b/MVMCoreUI/Styles/Padding.swift index 6ef0cc62..ca99d5dc 100644 --- a/MVMCoreUI/Styles/Padding.swift +++ b/MVMCoreUI/Styles/Padding.swift @@ -28,11 +28,11 @@ public struct Padding { public static let VerticalSpacing: CGFloat = 32 public static let VerticalSpacing3: CGFloat = 24 - public static var HorizontalPaddingForApplicationWidth: CGFloat { + public static var horizontalPaddingForApplicationWidth: CGFloat { return MFSizeObject(scalingStandardSize: HorizontalSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalSpacing } - public static var VerticalPaddingForApplicationWidth: CGFloat { + public static var verticalPaddingForApplicationWidth: CGFloat { return MFSizeObject(scalingStandardSize: VerticalSpacing)?.getValueBasedOnApplicationWidth() ?? VerticalSpacing } From 9f07e155789fe497fc78aebffbf647e3428d4852 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 6 Apr 2020 14:31:53 -0400 Subject: [PATCH 13/31] color added. --- MVMCoreUI/Categories/UIColor+MFConvenience.h | 1 + MVMCoreUI/Categories/UIColor+MFConvenience.m | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/MVMCoreUI/Categories/UIColor+MFConvenience.h b/MVMCoreUI/Categories/UIColor+MFConvenience.h index c3c78c7a..92b28a36 100644 --- a/MVMCoreUI/Categories/UIColor+MFConvenience.h +++ b/MVMCoreUI/Categories/UIColor+MFConvenience.h @@ -24,6 +24,7 @@ + (nonnull UIColor *)mvmOrange; + (nonnull UIColor *)mfPumpkinColor; + (nonnull UIColor *)mfShamrock; ++ (nonnull UIColor *)mvmGreen; + (nonnull UIColor *)mfCerulean; + (nonnull UIColor *)mfWhiteTwo; diff --git a/MVMCoreUI/Categories/UIColor+MFConvenience.m b/MVMCoreUI/Categories/UIColor+MFConvenience.m index 6ff8f70f..33df3848 100644 --- a/MVMCoreUI/Categories/UIColor+MFConvenience.m +++ b/MVMCoreUI/Categories/UIColor+MFConvenience.m @@ -61,6 +61,10 @@ return [UIColor mfColor8bitsWithRed:0 green:134 blue:49 alpha:1.0]; } ++ (nonnull UIColor *)mvmGreen { + return [UIColor mfColor8bitsWithRed:0 green:134 blue:48 alpha:1.0]; +} + + (nonnull UIColor *)mfCerulean { return [UIColor mfColor8bitsWithRed:0 green:122 blue:184 alpha:1.0]; } From 7a221da7ba330d8e5cb5ee5eb97560f7704b6277 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Mon, 6 Apr 2020 14:32:55 -0400 Subject: [PATCH 14/31] asd --- MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m index 930828f6..4e79ee6f 100644 --- a/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m +++ b/MVMCoreUI/TopAlert/MVMCoreUITopAlertView.m @@ -117,7 +117,7 @@ NSString * const MFAccTopAlertClosed = @"Top alert notification is closed."; if ([type isEqualToString:ValueTypeError]) { return [UIColor mvmOrange]; } else { - return [UIColor mfShamrock]; + return [UIColor mvmGreen]; } } From 9079d6dcae44899e35659d83fb0831007ee2e7ce Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 7 Apr 2020 11:22:01 -0400 Subject: [PATCH 15/31] more chanes made for design request --- .../Atomic/Atoms/Buttons/CaretLink.swift | 6 ++--- .../Atoms/TextFields/DigitEntryField.swift | 2 +- .../Atomic/Atoms/TextFields/EntryField.swift | 18 ++++++++------- .../Atoms/TextFields/TextEntryField.swift | 21 +++++++++++++----- MVMCoreUI/Atomic/Atoms/Views/Toggle.swift | 6 ++--- .../Views/EntryFieldContainer.swift | 22 +++++++++---------- 6 files changed, 43 insertions(+), 32 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift index 697f4282..2e042824 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift @@ -25,11 +25,11 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { @objc public var rightViewHeight: NSNumber? @objc public var rightViewWidth: NSNumber? - @objc public var enabledColor: UIColor = .black { + @objc public var enabledColor: UIColor = .mvmBlack { didSet { changeCaretColor() } } - @objc public var disabledColor: UIColor = .mfSilver() { + @objc public var disabledColor: UIColor = .mvmCoolGray3 { didSet { changeCaretColor() } } @@ -114,7 +114,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { caretView.widthAnchor.constraint(equalToConstant: width).isActive = true caretView.heightAnchor.constraint(equalToConstant: height).isActive = true - let caretLabelSpacing = NSLayoutConstraint(item: caretView, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 4) + let caretLabelSpacing = NSLayoutConstraint(item: caretView, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 7) caretLabelSpacing.isActive = true caretSpacingConstraint = caretLabelSpacing diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/DigitEntryField.swift b/MVMCoreUI/Atomic/Atoms/TextFields/DigitEntryField.swift index 091f9e51..38adee03 100644 --- a/MVMCoreUI/Atomic/Atoms/TextFields/DigitEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/TextFields/DigitEntryField.swift @@ -116,7 +116,7 @@ import UIKit for (index, field) in digitBoxes.enumerated() { if index < newValue.count { let indexChar = newValue.index(newValue.startIndex, offsetBy: index) - field.digitField.attributedPlaceholder = NSAttributedString(string: String(newValue[indexChar]), attributes: [NSAttributedString.Key.foregroundColor: UIColor.mfBattleshipGrey()]) + field.digitField.attributedPlaceholder = NSAttributedString(string: String(newValue[indexChar]), attributes: [NSAttributedString.Key.foregroundColor: UIColor.mvmCoolGray6]) } } diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift b/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift index 7fb3a458..658af357 100644 --- a/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift @@ -20,8 +20,8 @@ import UIKit public private(set) var titleLabel: Label = { let label = Label() - label.font = MFStyler.fontB3() - label.textColor = .mvmCoolGray6 + label.font = MFStyler.fontRegularMicro() + label.textColor = .mvmBlack label.setContentCompressionResistancePriority(.required, for: .vertical) return label }() @@ -31,7 +31,7 @@ import UIKit /// Provides contextual information on the TextField. public private(set) var feedbackLabel: Label = { let label = Label() - label.font = MFStyler.fontForTextFieldUnderLabel() + label.font = MFStyler.fontRegularMicro() label.textColor = .mvmBlack label.setContentCompressionResistancePriority(.required, for: .vertical) return label @@ -65,7 +65,8 @@ import UIKit public var isEnabled: Bool { get { return entryFieldContainer.isEnabled } set (enabled) { - self.feedbackLabel.textColor = enabled ? .black : .mfSilver() + self.titleLabel.textColor = enabled ? .mvmBlack : .mvmCoolGray3 + self.feedbackLabel.textColor = enabled ? .mvmBlack : .mvmCoolGray3 self.entryFieldContainer.isEnabled = enabled } } @@ -233,15 +234,16 @@ import UIKit //-------------------------------------------------- // MARK: - MoleculeViewProtocol //-------------------------------------------------- + @objc open override func reset() { super.reset() backgroundColor = .clear isAccessibilityElement = false - titleLabel.font = MFStyler.fontB3() - titleLabel.textColor = .mfBattleshipGrey() - feedbackLabel.font = MFStyler.fontForTextFieldUnderLabel() - feedbackLabel.textColor = .black + titleLabel.font = MFStyler.fontRegularMicro() + titleLabel.textColor = .mvmBlack + feedbackLabel.font = MFStyler.fontRegularMicro() + feedbackLabel.textColor = .mvmBlack entryFieldContainer.reset() } diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift b/MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift index 2e7df5ee..cf927c03 100644 --- a/MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift @@ -28,7 +28,8 @@ import UIKit let textField = TextField() textField.isAccessibilityElement = true textField.setContentCompressionResistancePriority(.required, for: .vertical) - textField.font = MFStyler.fontForTextField() + textField.font = MFStyler.fontRegularBodyLarge() + textField.textColor = .mvmBlack textField.smartQuotesType = .no textField.smartDashesType = .no textField.smartInsertDeleteType = .no @@ -40,7 +41,7 @@ import UIKit //-------------------------------------------------- /// Set enabled and disabled colors to be utilized when setting this texfield's isEnabled property. - public var textColor: (enabled: UIColor?, disabled: UIColor?) = (.black, .mfSilver()) + public var textColor: (enabled: UIColor?, disabled: UIColor?) = (.mvmBlack, .mvmCoolGray3) private var observingForChange: Bool = false @@ -78,7 +79,9 @@ import UIKit if error { textField.accessibilityValue = String(format: MVMCoreUIUtility.hardcodedString(withKey: "textfield_error_message") ?? "", textField.text ?? "", errorMessage ?? "") + errorIconWidthContraint?.constant = 20 } else { + errorIconWidthContraint?.constant = 0 textField.accessibilityValue = nil } @@ -140,6 +143,7 @@ import UIKit //-------------------------------------------------- public var textFieldTrailingConstraint: NSLayoutConstraint? + public var errorIconWidthContraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Initializers @@ -168,7 +172,7 @@ import UIKit @objc open override func setupFieldContainerContent(_ container: UIView) { - MFStyler.styleTextField(textField) + textField.font = MFStyler.fontRegularBodyLarge() container.addSubview(textField) NSLayoutConstraint.activate([ @@ -193,14 +197,14 @@ import UIKit @objc open override func updateView(_ size: CGFloat) { super.updateView(size) - MFStyler.styleTextField(textField) + textField.font = MFStyler.fontRegularBodyLarge() layoutIfNeeded() } open override func reset() { super.reset() - textField.font = MFStyler.fontForTextField() + textField.font = MFStyler.fontRegularBodyLarge() } @objc deinit { @@ -252,6 +256,7 @@ import UIKit observingTextFieldDelegate?.isValid?(textfield: self) } } + /// Executes on UITextField.textDidBeginEditingNotification @objc func startEditing() { isSelected = true @@ -270,7 +275,7 @@ import UIKit resignFirstResponder() if isValid { showError = false - entryFieldContainer.bottomBar?.backgroundColor = UIColor.black.cgColor + entryFieldContainer.bottomBar?.backgroundColor = UIColor.mvmBlack.cgColor } } @@ -278,6 +283,10 @@ import UIKit resignFirstResponder() } + //-------------------------------------------------- + // MARK: - MoleculeViewProtocol + //-------------------------------------------------- + public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift b/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift index 1e072faf..956c2afc 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Toggle.swift @@ -25,13 +25,13 @@ public typealias ActionBlockConfirmation = () -> (Bool) //-------------------------------------------------- /// Holds the on and off colors for the container. - public var containerTintColor: (on: UIColor?, off: UIColor?)? = (on: .mvmGreen, off: .black) + public var containerTintColor: (on: UIColor?, off: UIColor?)? = (on: .mvmGreen, off: .mvmBlack) /// Holds the on and off colors for the knob. - public var knobTintColor: (on: UIColor?, off: UIColor?)? = (on: .white, off: .white) + public var knobTintColor: (on: UIColor?, off: UIColor?)? = (on: .mvmWhite, off: .mvmWhite) /// Holds the on and off colors for the disabled state.. - public var disabledTintColor: (container: UIColor?, knob: UIColor?)? = (container: .mvmCoolGray3, knob: .white) + public var disabledTintColor: (container: UIColor?, knob: UIColor?)? = (container: .mvmCoolGray3, knob: .mvmWhite) /// Set this flag to false if you do not want to animate state changes. public var isAnimated = true diff --git a/MVMCoreUI/Containers/Views/EntryFieldContainer.swift b/MVMCoreUI/Containers/Views/EntryFieldContainer.swift index cf56fb9d..3a8fac64 100644 --- a/MVMCoreUI/Containers/Views/EntryFieldContainer.swift +++ b/MVMCoreUI/Containers/Views/EntryFieldContainer.swift @@ -17,7 +17,7 @@ import UIKit /// The bottom border line. Height is dynamic based on scenario. public var bottomBar: CAShapeLayer? = { let layer = CAShapeLayer() - layer.backgroundColor = UIColor.black.cgColor + layer.backgroundColor = UIColor.mvmBlack.cgColor layer.drawsAsynchronously = true layer.anchorPoint = CGPoint(x: 0.5, y: 1.0); return layer @@ -46,7 +46,7 @@ import UIKit /// Determines if the top, left, and right borders should be drawn. private var hideBorders = false - public var borderStrokeColor: UIColor = .mfSilver() + public var borderStrokeColor: UIColor = .mvmCoolGray3 private var borderPath: UIBezierPath = UIBezierPath() //-------------------------------------------------- @@ -210,8 +210,8 @@ import UIKit isUserInteractionEnabled = true hideBorders = false - borderStrokeColor = .mfSilver() - bottomBar?.backgroundColor = UIColor.black.cgColor + borderStrokeColor = .mvmCoolGray3 + bottomBar?.backgroundColor = UIColor.mvmBlack.cgColor refreshUI(bottomBarSize: 1) } @@ -219,8 +219,8 @@ import UIKit isUserInteractionEnabled = true hideBorders = false - borderStrokeColor = .mfPumpkin() - bottomBar?.backgroundColor = UIColor.mfPumpkin().cgColor + borderStrokeColor = .mvmOrange + bottomBar?.backgroundColor = UIColor.mvmOrange.cgColor refreshUI(bottomBarSize: 4) } @@ -228,8 +228,8 @@ import UIKit isUserInteractionEnabled = true hideBorders = false - borderStrokeColor = .black - bottomBar?.backgroundColor = UIColor.mfPumpkin().cgColor + borderStrokeColor = .mvmBlack + bottomBar?.backgroundColor = UIColor.mvmOrange.cgColor refreshUI(bottomBarSize: 4) } @@ -237,8 +237,8 @@ import UIKit isUserInteractionEnabled = true hideBorders = false - borderStrokeColor = .black - bottomBar?.backgroundColor = UIColor.black.cgColor + borderStrokeColor = .mvmBlack + bottomBar?.backgroundColor = UIColor.mvmBlack.cgColor refreshUI(bottomBarSize: 1) } @@ -255,7 +255,7 @@ import UIKit isUserInteractionEnabled = false hideBorders = false - borderStrokeColor = .mfSilver() + borderStrokeColor = .mvmCoolGray3 bottomBar?.backgroundColor = UIColor.mvmCoolGray3.cgColor refreshUI(bottomBarSize: 1) } From 1ac94059dbcc084aa5138e81ab435f42d2e1423b Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 7 Apr 2020 11:27:56 -0400 Subject: [PATCH 16/31] mild updates to caret --- .../Atomic/Atoms/Buttons/CaretLink.swift | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift index 2e042824..75c44eb3 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift @@ -103,8 +103,10 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { let width = CGFloat(rightViewWidth?.floatValue ?? CARET_VIEW_WIDTH) let height = CGFloat(rightViewHeight?.floatValue ?? CARET_VIEW_HEIGHT) - let edgeInsets: UIEdgeInsets = contentEdgeInsets - contentEdgeInsets = UIEdgeInsets(top: edgeInsets.top, left: edgeInsets.left, bottom: edgeInsets.bottom, right: 4 + width) + contentEdgeInsets = UIEdgeInsets(top: contentEdgeInsets.top, + left: contentEdgeInsets.left, + bottom: contentEdgeInsets.bottom, + right: 4 + width) let caretView: UIView = rightView ?? createCaretView() rightView = caretView @@ -118,8 +120,8 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { caretLabelSpacing.isActive = true caretSpacingConstraint = caretLabelSpacing - NSLayoutConstraint(item: caretView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0).isActive = true - NSLayoutConstraint(item: self, attribute: .right, relatedBy: .greaterThanOrEqual, toItem: caretView, attribute: .right, multiplier: 1.0, constant: 0).isActive = true + caretView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true + trailingAnchor.constraint(greaterThanOrEqualTo: caretView.trailingAnchor).isActive = true caretView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true bottomAnchor.constraint(greaterThanOrEqualTo: caretView.bottomAnchor).isActive = true contentHorizontalAlignment = .left @@ -137,17 +139,21 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { // MARK: - Atomization //------------------------------------------------------ public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - guard let caretLinkModel = model as? CaretLinkModel else { return } - if let color = caretLinkModel.backgroundColor { + + guard let model = model as? CaretLinkModel else { return } + + if let color = model.backgroundColor { backgroundColor = color.uiColor } - enabledColor = caretLinkModel.enabledColor.uiColor - if let color = caretLinkModel.disabledColor { + + enabledColor = model.enabledColor.uiColor + if let color = model.disabledColor { disabledColor = color.uiColor } - isEnabled = caretLinkModel.enabled - set(with: caretLinkModel.action, delegateObject: delegateObject, additionalData: additionalData) - setTitle(caretLinkModel.title, for: .normal) + + isEnabled = model.enabled + set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) + setTitle(model.title, for: .normal) } public func needsToBeConstrained() -> Bool { From 2b065d1b80032653eeafd623d10116509e04998b Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 7 Apr 2020 11:34:12 -0400 Subject: [PATCH 17/31] improvedment --- MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift index 75c44eb3..b437a56f 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift @@ -103,10 +103,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { let width = CGFloat(rightViewWidth?.floatValue ?? CARET_VIEW_WIDTH) let height = CGFloat(rightViewHeight?.floatValue ?? CARET_VIEW_HEIGHT) - contentEdgeInsets = UIEdgeInsets(top: contentEdgeInsets.top, - left: contentEdgeInsets.left, - bottom: contentEdgeInsets.bottom, - right: 4 + width) + contentEdgeInsets.right = 4 + width let caretView: UIView = rightView ?? createCaretView() rightView = caretView From 544a630ffb164ee59043773b2e47365e807e1520 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 7 Apr 2020 11:35:33 -0400 Subject: [PATCH 18/31] readable consteaint --- MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift index b437a56f..4ba95472 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift @@ -113,7 +113,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { caretView.widthAnchor.constraint(equalToConstant: width).isActive = true caretView.heightAnchor.constraint(equalToConstant: height).isActive = true - let caretLabelSpacing = NSLayoutConstraint(item: caretView, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 7) + let caretLabelSpacing = caretView.leadingAnchor.constraint(equalTo: titleLabel?.trailingAnchor, constant: 7) caretLabelSpacing.isActive = true caretSpacingConstraint = caretLabelSpacing From d96aa1c310687f34116245af8dd9e0fa47369a35 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 7 Apr 2020 11:36:34 -0400 Subject: [PATCH 19/31] undo --- MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift index 4ba95472..b437a56f 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/CaretLink.swift @@ -113,7 +113,7 @@ open class CaretLink: Button, MVMCoreUIViewConstrainingProtocol { caretView.widthAnchor.constraint(equalToConstant: width).isActive = true caretView.heightAnchor.constraint(equalToConstant: height).isActive = true - let caretLabelSpacing = caretView.leadingAnchor.constraint(equalTo: titleLabel?.trailingAnchor, constant: 7) + let caretLabelSpacing = NSLayoutConstraint(item: caretView, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 7) caretLabelSpacing.isActive = true caretSpacingConstraint = caretLabelSpacing From d9337cadff6bee8405d15840fa5bee0d8eaeb51c Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 7 Apr 2020 13:37:12 -0400 Subject: [PATCH 20/31] cleaning and revising donut --- MVMCoreUI.xcodeproj/project.pbxproj | 8 + .../Doughnut/ColorViewWithLabel.swift | 73 +++++ .../Molecules/Doughnut/DoughnutChart.swift | 292 ++++++++++-------- .../Doughnut/DoughnutChartItemModel.swift | 44 +++ .../Doughnut/DoughnutChartModel.swift | 24 +- .../Doughnut/DoughnutChartView.swift | 76 ++--- 6 files changed, 312 insertions(+), 205 deletions(-) create mode 100644 MVMCoreUI/Atomic/Molecules/Doughnut/ColorViewWithLabel.swift create mode 100644 MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartItemModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index c0a56ebc..67f83ce7 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -91,6 +91,8 @@ 0A6BF4722360C56C0028F841 /* BaseDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A6BF4712360C56C0028F841 /* BaseDropdownEntryField.swift */; }; 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */; }; 0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */; }; + 0A7ECC5D243CE85300C828E8 /* DoughnutChartItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7ECC5C243CE85300C828E8 /* DoughnutChartItemModel.swift */; }; + 0A7ECC5F243CEB1200C828E8 /* ColorViewWithLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7ECC5E243CEB1200C828E8 /* ColorViewWithLabel.swift */; }; 0A7EF85B23D8A52800B2AAD1 /* EntryFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7EF85A23D8A52800B2AAD1 /* EntryFieldModel.swift */; }; 0A7EF85D23D8A95600B2AAD1 /* TextEntryFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7EF85C23D8A95600B2AAD1 /* TextEntryFieldModel.swift */; }; 0A7EF85F23D8ABC500B2AAD1 /* MdnEntryFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A7EF85E23D8ABC500B2AAD1 /* MdnEntryFieldModel.swift */; }; @@ -488,6 +490,8 @@ 0A7BAD73232A8DC700FB8E22 /* HeadlineBodyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyButton.swift; sourceTree = ""; }; 0A7BAFA0232BE61800FB8E22 /* Checkbox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Checkbox.swift; sourceTree = ""; }; 0A7BAFA2232BE63400FB8E22 /* CheckboxLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxLabel.swift; sourceTree = ""; }; + 0A7ECC5C243CE85300C828E8 /* DoughnutChartItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoughnutChartItemModel.swift; sourceTree = ""; }; + 0A7ECC5E243CEB1200C828E8 /* ColorViewWithLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorViewWithLabel.swift; sourceTree = ""; }; 0A7EF85A23D8A52800B2AAD1 /* EntryFieldModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryFieldModel.swift; sourceTree = ""; }; 0A7EF85C23D8A95600B2AAD1 /* TextEntryFieldModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextEntryFieldModel.swift; sourceTree = ""; }; 0A7EF85E23D8ABC500B2AAD1 /* MdnEntryFieldModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MdnEntryFieldModel.swift; sourceTree = ""; }; @@ -1340,9 +1344,11 @@ D260105723CF9CC500764D80 /* Doughnut */ = { isa = PBXGroup; children = ( + 0A7ECC5C243CE85300C828E8 /* DoughnutChartItemModel.swift */, C695A69323C9909000BFB94E /* DoughnutChartModel.swift */, C695A69523C990BC00BFB94E /* DoughnutChart.swift */, C695A69723C990C200BFB94E /* DoughnutChartView.swift */, + 0A7ECC5E243CEB1200C828E8 /* ColorViewWithLabel.swift */, ); path = Doughnut; sourceTree = ""; @@ -2067,6 +2073,7 @@ D268C70C2386DFFD007F2C1C /* MoleculeStackItemModel.swift in Sources */, DBEFFA04225A829700230692 /* Label.swift in Sources */, D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */, + 0A7ECC5D243CE85300C828E8 /* DoughnutChartItemModel.swift in Sources */, 0A7EF85F23D8ABC500B2AAD1 /* MdnEntryFieldModel.swift in Sources */, 011D959B240451E3000E3791 /* RuleRequiredModel.swift in Sources */, 526A265C240D1FF700B0D828 /* ListTwoColumnCompareChangesModel.swift in Sources */, @@ -2173,6 +2180,7 @@ C695A67F23C9830600BFB94E /* UnOrderedListModel.swift in Sources */, 0AE98BB523FF18D2004C5109 /* Arrow.swift in Sources */, D2D90B442404789000DD6EC9 /* MoleculeContainerProtocol.swift in Sources */, + 0A7ECC5F243CEB1200C828E8 /* ColorViewWithLabel.swift in Sources */, 94C0150A24215643005811A9 /* ActionTopAlertModel.swift in Sources */, 012A88DB238ED45900FE3DA1 /* CarouselModel.swift in Sources */, D29DF28C21E7AC2B003B2FB9 /* ViewConstrainingView.m in Sources */, diff --git a/MVMCoreUI/Atomic/Molecules/Doughnut/ColorViewWithLabel.swift b/MVMCoreUI/Atomic/Molecules/Doughnut/ColorViewWithLabel.swift new file mode 100644 index 00000000..f8dd4b5c --- /dev/null +++ b/MVMCoreUI/Atomic/Molecules/Doughnut/ColorViewWithLabel.swift @@ -0,0 +1,73 @@ +// +// ColorViewWithLabel.swift +// MVMCoreUI +// +// Created by Kevin Christiano on 4/7/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + + +open class ColorViewWithLabel: View { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public var label = Label.createLabelRegularBodySmall(true) + public var colorView = View() + private var sizeObject = MFStyler.sizeObjectGeneric(forCurrentDevice: 8)! + + //-------------------------------------------------- + // MARK: - Lifecycle + //-------------------------------------------------- + + public var heightConstraint: NSLayoutConstraint? + + //-------------------------------------------------- + // MARK: - Lifecycle + //-------------------------------------------------- + + open override func setupView() { + super.setupView() + + addSubview(colorView) + addSubview(label) + + heightConstraint = colorView.heightAnchor.constraint(equalToConstant: sizeObject.getValueBasedOnApplicationWidth()) + heightConstraint?.isActive = true + colorView.widthAnchor.constraint(equalTo: colorView.heightAnchor).isActive = true + colorView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + colorView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true + + label.leadingAnchor.constraint(equalTo: colorView.trailingAnchor, constant: PaddingOne).isActive = true + label.topAnchor.constraint(equalTo: topAnchor).isActive = true + trailingAnchor.constraint(equalTo: label.trailingAnchor).isActive = true + bottomAnchor.constraint(equalTo: label.bottomAnchor).isActive = true + } + + open override func updateView(_ size: CGFloat) { + super.updateView(size) + label.updateView(size) + heightConstraint?.constant = sizeObject.getValueBased(onSize: size) + setNeedsDisplay() + } + + open override func reset() { + super.reset() + label.reset() + } + + //-------------------------------------------------- + // MARK: - MoleculeViewProtocol + //-------------------------------------------------- + + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + super.set(with: model, delegateObject, additionalData) + + guard let chartItemModel = model as? DoughnutChartItemModel else { return } + + label.set(with: chartItemModel.label, delegateObject, additionalData) + colorView.backgroundColor = chartItemModel.color.uiColor + } +} diff --git a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift index d84c7dc0..c7025b0f 100644 --- a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift +++ b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift @@ -8,23 +8,38 @@ import UIKit + open class DoughnutChart: View { - var doughnutLayer = CALayer() - var titleLabel = Label.commonLabelH3(true) - var subTitleLabel = Label.commonLabelB2(true) - var doughnutChartModel: DoughnutChartModel? { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public var doughnutLayer = CALayer() + public var titleLabel = Label.createLabelRegularTitleLarge(true) + public var subTitleLabel = Label.createLabelRegularMicro(true) + public var labelContainer = View() + public static let heightConstant: CGFloat = 136 + private var sizeObject = MFStyler.sizeObjectGeneric(forCurrentDevice: heightConstant)! + + //-------------------------------------------------- + // MARK: - Constraints + //-------------------------------------------------- + + public var labelContainerLeftConstraint: NSLayoutConstraint? + public var labelContainerTopConstraint: NSLayoutConstraint? + public var labelContainerBottomConstraint: NSLayoutConstraint? + public var labelContainerRightConstraint: NSLayoutConstraint? + public var heightConstraint: NSLayoutConstraint? + + //-------------------------------------------------- + // MARK: - Computed Properties + //-------------------------------------------------- + + public var doughnutChartModel: DoughnutChartModel? { get { return model as? DoughnutChartModel } - } - var labelContainer = MVMCoreUICommonViewsUtility.commonView() - var labelContainerLeftConstraint: NSLayoutConstraint? - var labelContainerTopConstraint: NSLayoutConstraint? - var labelContainerBottomConstraint: NSLayoutConstraint? - var labelContainerRightConstraint: NSLayoutConstraint? - var heightConstraint: NSLayoutConstraint? - - static let heightConstant: CGFloat = 150 - private var sizeObject = MFStyler.sizeObjectGeneric(forCurrentDevice: heightConstant)! - var height: CGFloat = heightConstant { + } + + public var height: CGFloat = heightConstant { didSet { if height != oldValue { sizeObject = MFStyler.sizeObjectGeneric(forCurrentDevice: height)! @@ -32,69 +47,73 @@ open class DoughnutChart: View { drawGraph() } } - } - - open override func updateView(_ size: CGFloat) { - super.updateView(size) - titleLabel.updateView(size) - subTitleLabel.updateView(size) - updateContainer() - drawGraph() - } - - open override func reset() { - super.reset() - titleLabel.reset() - subTitleLabel.reset() - clearLayers() - } - - open override func setupView() { - super.setupView() - guard labelContainer.superview == nil else { - return - } - addSubview(labelContainer) - - labelContainer.addSubview(titleLabel) - labelContainer.addSubview(subTitleLabel) - titleLabel.textAlignment = .center - subTitleLabel.textAlignment = .center - - //Make label font size to adjust width if label content is high - titleLabel.numberOfLines = 1 - titleLabel.adjustsFontSizeToFitWidth = true - - layer.addSublayer(doughnutLayer) - heightConstraint = heightAnchor.constraint(equalToConstant: - sizeObject.getValueBasedOnApplicationWidth()) - heightConstraint?.isActive = true - widthAnchor.constraint(equalTo: heightAnchor).isActive = true - - labelContainerLeftConstraint = labelContainer.leftAnchor.constraint(greaterThanOrEqualTo: leftAnchor, constant: lineWidth()) - labelContainerLeftConstraint?.isActive = true - labelContainerTopConstraint = labelContainer.topAnchor.constraint(greaterThanOrEqualTo: topAnchor, constant: lineWidth()) - labelContainerTopConstraint?.isActive = true - labelContainerRightConstraint = rightAnchor.constraint(greaterThanOrEqualTo: labelContainer.rightAnchor, constant: lineWidth()) - labelContainerRightConstraint?.isActive = true - labelContainerBottomConstraint = bottomAnchor.constraint(greaterThanOrEqualTo: labelContainer.bottomAnchor, constant: lineWidth()) - labelContainerBottomConstraint?.isActive = true - labelContainer.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true - labelContainer.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true - - NSLayoutConstraint.constraintPinSubview(titleLabel, pinTop: true, pinBottom: false, pinLeft: true, pinRight: true) - NSLayoutConstraint.constraintPinSubview(subTitleLabel, pinTop: false, pinBottom: true, pinLeft: true, pinRight: true) - _ = NSLayoutConstraint(pinFirstView: titleLabel, toSecondView: subTitleLabel, withConstant: 0, directionVertical: true) - //Rotate view for initial draw - doughnutLayer.transform = CATransform3DMakeRotation(1 * .pi, 0.0, 0.0, 1.0) } - open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + //-------------------------------------------------- + // MARK: - Lifecycle + //-------------------------------------------------- + + open override func updateView(_ size: CGFloat) { + super.updateView(size) + titleLabel.updateView(size) + subTitleLabel.updateView(size) + updateContainer() + drawGraph() + } + + open override func reset() { + super.reset() + titleLabel.reset() + subTitleLabel.reset() + clearLayers() + } + + open override func setupView() { + super.setupView() + + addSubview(labelContainer) + + labelContainer.addSubview(titleLabel) + labelContainer.addSubview(subTitleLabel) + titleLabel.textAlignment = .center + subTitleLabel.textAlignment = .center + + //Make label font size to adjust width if label content is high + titleLabel.numberOfLines = 1 + titleLabel.adjustsFontSizeToFitWidth = true + + layer.addSublayer(doughnutLayer) + heightConstraint = heightAnchor.constraint(equalToConstant: sizeObject.getValueBasedOnApplicationWidth()) + heightConstraint?.isActive = true + widthAnchor.constraint(equalTo: heightAnchor).isActive = true + + labelContainerLeftConstraint = labelContainer.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor, constant: lineWidth()) + labelContainerLeftConstraint?.isActive = true + labelContainerTopConstraint = labelContainer.topAnchor.constraint(greaterThanOrEqualTo: topAnchor, constant: lineWidth()) + labelContainerTopConstraint?.isActive = true + labelContainerRightConstraint = trailingAnchor.constraint(greaterThanOrEqualTo: labelContainer.trailingAnchor, constant: lineWidth()) + labelContainerRightConstraint?.isActive = true + labelContainerBottomConstraint = bottomAnchor.constraint(greaterThanOrEqualTo: labelContainer.bottomAnchor, constant: lineWidth()) + labelContainerBottomConstraint?.isActive = true + labelContainer.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true + labelContainer.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true + + NSLayoutConstraint.constraintPinSubview(titleLabel, pinTop: true, pinBottom: false, pinLeft: true, pinRight: true) + NSLayoutConstraint.constraintPinSubview(subTitleLabel, pinTop: false, pinBottom: true, pinLeft: true, pinRight: true) + _ = NSLayoutConstraint(pinFirstView: titleLabel, toSecondView: subTitleLabel, withConstant: 0, directionVertical: true) + //Rotate view for initial draw + doughnutLayer.transform = CATransform3DMakeRotation(1 * .pi, 0, 0, 1) + } + + //-------------------------------------------------- + // MARK: - MoleculeViewProtocol + //-------------------------------------------------- + + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) clearLayers() - guard let doughnutChartModel = doughnutChartModel else { - return - } + guard let doughnutChartModel = doughnutChartModel else { return } + titleLabel.setOptional(with: doughnutChartModel.title, delegateObject, additionalData) subTitleLabel.setOptional(with: doughnutChartModel.subtitle, delegateObject, additionalData) titleLabel.textAlignment = .center @@ -103,78 +122,83 @@ open class DoughnutChart: View { drawGraph() } - func drawGraph() { - clearLayers() - let widthHeight = sizeObject.getValueBasedOnApplicationWidth() - doughnutLayer.frame = CGRect(x: 0, y: 0, - width: widthHeight, - height: widthHeight) - if let doughnutChart = doughnutChartModel { - var prevPercent: CGFloat = 0.0 - for model in doughnutChart.sections { + //-------------------------------------------------- + // MARK: - Draw Graph + //-------------------------------------------------- + + private func drawGraph() { + clearLayers() + let widthHeight = sizeObject.getValueBasedOnApplicationWidth() + doughnutLayer.frame = CGRect(x: 0, y: 0, width: widthHeight, height: widthHeight) + + if let doughnutChart = doughnutChartModel { + var prevPercent: CGFloat = 0.0 + for model in doughnutChart.sections { prevPercent += drawBar(model, prevPercent) - } - } - } - - func drawBar(_ chartModel: DoughnutChartItemModel, _ prevPercent: CGFloat) -> CGFloat { - - let shapeLayer = CAShapeLayer() - shapeLayer.frame = doughnutLayer.frame - shapeLayer.lineWidth = lineWidth() - shapeLayer.fillColor = nil - shapeLayer.strokeColor = chartModel.color.uiColor.cgColor - - let arcCenter = shapeLayer.position - let radius = shapeLayer.bounds.size.width / 2.0 - lineWidth()/2.0 - - let value: CGFloat = chartModel.percent - let gap: CGFloat = spaceRequired() ? lineGap() : 0.0 - let startAngle = ((prevPercent / 100.0) * 2 * .pi) - (0.5 * .pi) - let endAngle = ((value / 100.0) * 2 * .pi) + startAngle - gap - let circlePath = UIBezierPath(arcCenter: arcCenter, - radius: radius, - startAngle: startAngle, - endAngle: endAngle, - clockwise: true) - - shapeLayer.path = circlePath.cgPath - doughnutLayer.addSublayer(shapeLayer) - return value - } - - func clearLayers() { - doughnutLayer.sublayers?.forEach({ $0.removeFromSuperlayer() }) - } + } + } + } - func updateContainer() { - heightConstraint?.constant = sizeObject.getValueBasedOnApplicationWidth() - updateLabelContainer() - setNeedsDisplay() - } + private func drawBar(_ chartModel: DoughnutChartItemModel, _ prevPercent: CGFloat) -> CGFloat { + + let shapeLayer = CAShapeLayer() + shapeLayer.frame = doughnutLayer.frame + shapeLayer.lineWidth = lineWidth() + shapeLayer.fillColor = nil + shapeLayer.strokeColor = chartModel.color.uiColor.cgColor + + let arcCenter = shapeLayer.position + let radius = shapeLayer.bounds.size.width / 2.0 - lineWidth() / 2.0 + + let value: CGFloat = chartModel.percent + let gap: CGFloat = spaceRequired() ? lineGap() : 0.0 + let startAngle = ((prevPercent / 100.0) * 2 * .pi) - (0.5 * .pi) + let endAngle = ((value / 100.0) * 2 * .pi) + startAngle - gap + let circlePath = UIBezierPath(arcCenter: arcCenter, + radius: radius, + startAngle: startAngle, + endAngle: endAngle, + clockwise: true) + + shapeLayer.path = circlePath.cgPath + doughnutLayer.addSublayer(shapeLayer) + return value + } - func lineWidth() -> CGFloat { - return 30 - } + private func clearLayers() { + doughnutLayer.sublayers?.forEach{ $0.removeFromSuperlayer() } + } - func lineGap() -> CGFloat { + public func updateContainer() { + + heightConstraint?.constant = sizeObject.getValueBasedOnApplicationWidth() + updateLabelContainer() + setNeedsDisplay() + } + + public func lineWidth() -> CGFloat { + return 12 + } + + public func lineGap() -> CGFloat { //If array is having the single item then no space required return doughnutChartModel?.sections.count == 1 ? 0.0 : 0.05 - } + } - func spaceRequired() -> Bool { + public func spaceRequired() -> Bool { return doughnutChartModel?.spaceRequired ?? true - } + } - func updateLabelContainer() { + public func updateLabelContainer() { + labelContainer.setNeedsDisplay() labelContainer.layoutIfNeeded() - let radius = sizeObject.getValueBasedOnApplicationWidth()/2 - lineWidth() - let labelheight = labelContainer.frame.height/2 - let padding = sizeObject.getValueBasedOnApplicationWidth()/2 - sqrt(max(0, pow(radius, 2) - pow(labelheight, 2))) + let radius = sizeObject.getValueBasedOnApplicationWidth() / 2 - lineWidth() + let labelheight = labelContainer.frame.height / 2 + let padding = sizeObject.getValueBasedOnApplicationWidth() / 2 - sqrt(max(0, pow(radius, 2) - pow(labelheight, 2))) - labelContainerLeftConstraint?.constant = padding - labelContainerRightConstraint?.constant = padding + labelContainerLeftConstraint?.constant = round(padding) + labelContainerRightConstraint?.constant = round(padding) labelContainerTopConstraint?.constant = max(radius - labelheight, labelheight) labelContainerBottomConstraint?.constant = max(radius - labelheight, labelheight) } diff --git a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartItemModel.swift b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartItemModel.swift new file mode 100644 index 00000000..ee4e664a --- /dev/null +++ b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartItemModel.swift @@ -0,0 +1,44 @@ +// +// DoughnutChartItemModel.swift +// MVMCoreUI +// +// Created by Kevin Christiano on 4/7/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import Foundation + + +@objcMembers public class DoughnutChartItemModel: MoleculeModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public var backgroundColor: Color? + public static var identifier: String = "doughnutChartItem" + public var moleculeName: String = DoughnutChartItemModel.identifier + public var label: LabelModel + @Percent public var percent: CGFloat + public var color: Color + + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + + private enum CodingKeys: String, CodingKey { + case backgroundColor + case label + case percent + case color + } + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + + public init(percent: CGFloat, color: Color, label: LabelModel) { + self.percent = percent + self.color = color + self.label = label + } +} diff --git a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartModel.swift b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartModel.swift index ff9b1bf6..fbb034c6 100644 --- a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartModel.swift +++ b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartModel.swift @@ -8,7 +8,12 @@ import Foundation + @objcMembers public class DoughnutChartModel: MoleculeModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public var backgroundColor: Color? public static var identifier: String = "doughnutChart" public var moleculeName: String = DoughnutChartModel.identifier @@ -17,22 +22,11 @@ import Foundation public var sections: [DoughnutChartItemModel] public var spaceRequired: Bool? + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + public init(sections: [DoughnutChartItemModel]) { self.sections = sections } } - -@objcMembers public class DoughnutChartItemModel: MoleculeModelProtocol { - public var backgroundColor: Color? - public static var identifier: String = "doughnutChartItem" - public var moleculeName: String = DoughnutChartItemModel.identifier - public var label: LabelModel - @Percent public var percent: CGFloat - public var color: Color - - public init(percent: CGFloat, color: Color, label: LabelModel) { - self.percent = percent - self.color = color - self.label = label - } -} diff --git a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift index 280385cb..e037c984 100644 --- a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift +++ b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift @@ -8,18 +8,26 @@ import Foundation + @objcMembers open class DoughnutChartView: View { - var doughnutChart = DoughnutChart(frame: CGRect.zero) + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + var doughnutChart = DoughnutChart(frame: .zero) var colorLablesStack = ColorViewLabelsStack() + var doughnutChartModel: DoughnutChartModel? { - get { return model as? DoughnutChartModel } + get { return model as? DoughnutChartModel } } + //-------------------------------------------------- + // MARK: - Lifecycle + //-------------------------------------------------- + open override func setupView() { super.setupView() - guard doughnutChart.superview == nil else { - return - } + doughnutChart.translatesAutoresizingMaskIntoConstraints = false addSubview(doughnutChart) colorLablesStack.translatesAutoresizingMaskIntoConstraints = false @@ -65,12 +73,16 @@ import Foundation colorLablesStack.reset() } + //-------------------------------------------------- + // MARK: - MoleculeViewProtocol + //-------------------------------------------------- + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { super.set(with: model, delegateObject, additionalData) guard let model = doughnutChartModel else { return } doughnutChart.set(with: model, delegateObject, additionalData) - + // Create the stack model var stackItems: [MoleculeStackItemModel] = [] for item in model.sections { @@ -82,6 +94,7 @@ import Foundation } } +// MARK: - MVMCoreUIViewConstrainingProtocol extension DoughnutChartView: MVMCoreUIViewConstrainingProtocol { open func horizontalAlignment() -> UIStackView.Alignment { return .leading @@ -89,6 +102,7 @@ extension DoughnutChartView: MVMCoreUIViewConstrainingProtocol { } class ColorViewLabelsStack: MoleculeStackView { + override func createStackItemsFromModel(_ model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { guard let stackItemModels = stackModel?.molecules else { return } for model in stackItemModels { @@ -99,53 +113,3 @@ class ColorViewLabelsStack: MoleculeStackView { } } } - -class ColorViewWithLabel: View { - - var label = Label.commonLabelB2(true) - var colorView = MVMCoreUICommonViewsUtility.commonView() - private var sizeObject = MFStyler.sizeObjectGeneric(forCurrentDevice: 8)! - var heightConstraint: NSLayoutConstraint? - - override func setupView() { - super.setupView() - guard colorView.superview == nil else { - return - } - translatesAutoresizingMaskIntoConstraints = false - addSubview(colorView) - addSubview(label) - - heightConstraint = colorView.heightAnchor.constraint(equalToConstant: sizeObject.getValueBasedOnApplicationWidth()) - heightConstraint?.isActive = true - colorView.widthAnchor.constraint(equalTo: colorView.heightAnchor).isActive = true - colorView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true - colorView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true - - label.leadingAnchor.constraint(equalTo: colorView.trailingAnchor, constant: PaddingOne).isActive = true - label.topAnchor.constraint(equalTo: topAnchor).isActive = true - trailingAnchor.constraint(equalTo: label.trailingAnchor).isActive = true - bottomAnchor.constraint(equalTo: label.bottomAnchor).isActive = true - } - - override func updateView(_ size: CGFloat) { - super.updateView(size) - label.updateView(size) - heightConstraint?.constant = sizeObject.getValueBased(onSize: size) - setNeedsDisplay() - } - - override func reset() { - super.reset() - label.reset() - } - - override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { - super.set(with: model, delegateObject, additionalData) - guard let chartItemModel = model as? DoughnutChartItemModel else { - return - } - label.set(with: chartItemModel.label, delegateObject, additionalData) - colorView.backgroundColor = chartItemModel.color.uiColor - } -} From f125d55962e7b8f43885429c38de7b0442c3d395 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 7 Apr 2020 14:10:32 -0400 Subject: [PATCH 21/31] improved constraints to center align as requested by design --- .../Molecules/Doughnut/DoughnutChart.swift | 18 ++++++++++++++++- .../Doughnut/DoughnutChartView.swift | 20 +++++++++---------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift index c7025b0f..2908a90d 100644 --- a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift +++ b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift @@ -15,7 +15,7 @@ open class DoughnutChart: View { //-------------------------------------------------- public var doughnutLayer = CALayer() - public var titleLabel = Label.createLabelRegularTitleLarge(true) + public var titleLabel = Label.createLabelBoldTitleLarge(true) public var subTitleLabel = Label.createLabelRegularMicro(true) public var labelContainer = View() public static let heightConstant: CGFloat = 136 @@ -49,6 +49,22 @@ open class DoughnutChart: View { } } + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + + public override init(frame: CGRect) { + super.init(frame: .zero) + } + + public convenience init() { + self.init(frame: .zero) + } + + public required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- diff --git a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift index e037c984..2b3afdd5 100644 --- a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift +++ b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift @@ -28,35 +28,33 @@ import Foundation open override func setupView() { super.setupView() - doughnutChart.translatesAutoresizingMaskIntoConstraints = false addSubview(doughnutChart) - colorLablesStack.translatesAutoresizingMaskIntoConstraints = false addSubview(colorLablesStack) doughnutChart.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true - doughnutChart.topAnchor.constraint(equalTo: topAnchor).isActive = true + doughnutChart.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true + bottomAnchor.constraint(greaterThanOrEqualTo: doughnutChart.bottomAnchor).isActive = true let doughnutBottomAnchor = bottomAnchor.constraint(equalTo: doughnutChart.bottomAnchor) doughnutBottomAnchor.priority = UILayoutPriority(rawValue: 200) doughnutBottomAnchor.isActive = true + bottomAnchor.constraint(greaterThanOrEqualTo: colorLablesStack.bottomAnchor).isActive = true + let colorLablesBottomAnchor = bottomAnchor.constraint(equalTo: colorLablesStack.bottomAnchor) colorLablesBottomAnchor.priority = UILayoutPriority(rawValue: 204) colorLablesBottomAnchor.isActive = true - let colorLablesTopAnchor = colorLablesStack.topAnchor.constraint(equalTo: doughnutChart.topAnchor) + colorLablesStack.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true + + let colorLablesTopAnchor = colorLablesStack.topAnchor.constraint(equalTo: topAnchor) colorLablesTopAnchor.priority = .defaultLow colorLablesTopAnchor.isActive = true - colorLablesStack.topAnchor.constraint(greaterThanOrEqualTo: doughnutChart.topAnchor).isActive = true - bottomAnchor.constraint(greaterThanOrEqualTo: colorLablesStack.bottomAnchor).isActive = true trailingAnchor.constraint(equalTo: colorLablesStack.trailingAnchor).isActive = true - - let centerY = colorLablesStack.centerYAnchor.constraint(equalTo: doughnutChart.centerYAnchor) - centerY.priority = UILayoutPriority(rawValue: 500) - centerY.isActive = true - + doughnutChart.centerYAnchor.constraint(equalTo: colorLablesStack.centerYAnchor).isActive = true + colorLablesStack.leadingAnchor.constraint(equalTo: doughnutChart.trailingAnchor, constant: PaddingThree).isActive = true colorLablesStack.backgroundColor = .clear } From 752ff76e79f6bac7f1a6724a0fca3a4e108ad5dc Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 7 Apr 2020 14:22:06 -0400 Subject: [PATCH 22/31] access modified --- .../Atomic/Molecules/Doughnut/DoughnutChartView.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift index 2b3afdd5..1c0ea963 100644 --- a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift +++ b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChartView.swift @@ -14,10 +14,10 @@ import Foundation // MARK: - Properties //-------------------------------------------------- - var doughnutChart = DoughnutChart(frame: .zero) + public var doughnutChart = DoughnutChart() var colorLablesStack = ColorViewLabelsStack() - var doughnutChartModel: DoughnutChartModel? { + public var doughnutChartModel: DoughnutChartModel? { get { return model as? DoughnutChartModel } } @@ -75,7 +75,7 @@ import Foundation // MARK: - MoleculeViewProtocol //-------------------------------------------------- - open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) guard let model = doughnutChartModel else { return } @@ -94,6 +94,7 @@ import Foundation // MARK: - MVMCoreUIViewConstrainingProtocol extension DoughnutChartView: MVMCoreUIViewConstrainingProtocol { + open func horizontalAlignment() -> UIStackView.Alignment { return .leading } @@ -101,7 +102,7 @@ extension DoughnutChartView: MVMCoreUIViewConstrainingProtocol { class ColorViewLabelsStack: MoleculeStackView { - override func createStackItemsFromModel(_ model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { + override func createStackItemsFromModel(_ model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let stackItemModels = stackModel?.molecules else { return } for model in stackItemModels { let view = ColorViewWithLabel() From 8072d8d4aa585a19df1a7e55d5748e7d7d0cf5ba Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 7 Apr 2020 14:33:57 -0400 Subject: [PATCH 23/31] organized radio --- .../Atomic/Atoms/Buttons/RadioButton.swift | 23 +++++++-------- .../Buttons/RadioButtonSelectionHelper.swift | 28 ++++++++++++++----- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift index 98532549..b73ddc8b 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButton.swift @@ -8,6 +8,7 @@ import UIKit + @objcMembers open class RadioButton: Control { //-------------------------------------------------- // MARK: - Properties @@ -18,19 +19,19 @@ import UIKit widthConstraint?.constant = diameter } } - - public var enabledColor: UIColor = .black - public var disabledColor: UIColor = .mfSilver() + + public var enabledColor: UIColor = .mvmBlack + public var disabledColor: UIColor = .mvmCoolGray6 public var delegateObject: MVMCoreUIDelegateObject? public var radioModel: RadioButtonModel? { return model as? RadioButtonModel } - + lazy public var radioGroupName: String? = { return radioModel?.fieldKey }() - + lazy public var radioButtonSelectionHelper: RadioButtonSelectionHelper? = { if let radioGroupName = radioGroupName, let radioButtonModel = delegateObject?.formHolderDelegate?.formValidator?.radioButtonsModelByGroup[radioGroupName] { @@ -100,7 +101,7 @@ import UIKit public func formFieldValue() -> AnyHashable? { return radioModel?.fieldValue } - + //-------------------------------------------------- // MARK: - MVMViewProtocol //-------------------------------------------------- @@ -108,7 +109,7 @@ import UIKit open override func setupView() { super.setupView() - backgroundColor = .white + backgroundColor = .mvmWhite clipsToBounds = true widthConstraint = widthAnchor.constraint(equalToConstant: 30) widthConstraint?.isActive = true @@ -120,7 +121,7 @@ import UIKit accessibilityTraits = .button accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "radio_action_hint") } - + public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) @@ -130,9 +131,9 @@ import UIKit isSelected = model.state RadioButtonSelectionHelper.setupForRadioButtonGroup(model, self, delegateObject: delegateObject) } - + public override func reset() { - super.reset() - backgroundColor = .white + super.reset() + backgroundColor = .white } } diff --git a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift index 3decadb5..c7208802 100644 --- a/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift +++ b/MVMCoreUI/Atomic/Atoms/Buttons/RadioButtonSelectionHelper.swift @@ -7,29 +7,41 @@ // import Foundation -import UIKit + @objcMembers public class RadioButtonSelectionHelper: FormFieldProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + public var fieldKey: String? public var groupName: String = FormValidator.defaultGroupName private var selectedRadioButton: RadioButton? private var fieldGroupName: String? public var baseValue: AnyHashable? - + + //-------------------------------------------------- + // MARK: - Initializer + //-------------------------------------------------- + init(_ fieldKey: String?) { self.fieldKey = fieldKey } + //-------------------------------------------------- + // MARK: - Methods + //-------------------------------------------------- + public static func setupForRadioButtonGroup(_ radioButtonModel: RadioButtonModel, _ radioButton: RadioButton, delegateObject: MVMCoreUIDelegateObject?) { + guard let groupName = radioButtonModel.fieldKey, - let formValidator = delegateObject?.formHolderDelegate?.formValidator else { - return - } + let formValidator = delegateObject?.formHolderDelegate?.formValidator + else { return } let radioButtonSelectionHelper = formValidator.radioButtonsModelByGroup[groupName] ?? RadioButtonSelectionHelper(radioButtonModel.fieldKey) radioButtonSelectionHelper.fieldGroupName = radioButtonModel.fieldKey formValidator.radioButtonsModelByGroup[groupName] = radioButtonSelectionHelper - + if radioButtonModel.state { radioButtonSelectionHelper.selectedRadioButton = radioButton } @@ -37,6 +49,7 @@ import UIKit } public func selected(_ radioButton: RadioButton) { + selectedRadioButton?.isSelected = false selectedRadioButton = radioButton selectedRadioButton?.isSelected = true @@ -45,8 +58,9 @@ import UIKit // MARK: - FormValidationFormFieldProtocol extension RadioButtonSelectionHelper { + public func formFieldGroupName() -> String? { - return selectedRadioButton?.formFieldGroupName() ?? self.fieldGroupName + return selectedRadioButton?.formFieldGroupName() ?? fieldGroupName } public func formFieldValue() -> AnyHashable? { From 6ca54fce6a4679ddb01c31dec363297e4bc406d2 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 7 Apr 2020 15:22:33 -0400 Subject: [PATCH 24/31] settingup new accessor --- MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift b/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift index 658af357..c12b7dd3 100644 --- a/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift @@ -57,6 +57,12 @@ import UIKit } } + public var accessoryInput: View? { + didSet { + + } + } + //-------------------------------------------------- // MARK: - Computed Properties //-------------------------------------------------- @@ -209,6 +215,9 @@ import UIKit feedbackLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: feedbackLabel.trailingAnchor) feedbackLabelTrailing?.isActive = true layoutMarginsGuide.bottomAnchor.constraint(equalTo: feedbackLabel.bottomAnchor).isActive = true + + container.trailingAnchor.constraint(equalTo: dropDownCaretView.trailingAnchor, constant: 16).isActive = true + dropDownCaretView.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true } @objc open override func layoutSubviews() { From dcf168b53ecec3030eaddf717e8446ee400c35cc Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 8 Apr 2020 08:19:06 -0400 Subject: [PATCH 25/31] rolaback --- MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift | 3 --- MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift | 3 --- MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift b/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift index c12b7dd3..da46c26e 100644 --- a/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift @@ -215,9 +215,6 @@ import UIKit feedbackLabelTrailing = layoutMarginsGuide.trailingAnchor.constraint(equalTo: feedbackLabel.trailingAnchor) feedbackLabelTrailing?.isActive = true layoutMarginsGuide.bottomAnchor.constraint(equalTo: feedbackLabel.bottomAnchor).isActive = true - - container.trailingAnchor.constraint(equalTo: dropDownCaretView.trailingAnchor, constant: 16).isActive = true - dropDownCaretView.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true } @objc open override func layoutSubviews() { diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift b/MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift index cf927c03..de0d1789 100644 --- a/MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/TextFields/TextEntryField.swift @@ -79,9 +79,7 @@ import UIKit if error { textField.accessibilityValue = String(format: MVMCoreUIUtility.hardcodedString(withKey: "textfield_error_message") ?? "", textField.text ?? "", errorMessage ?? "") - errorIconWidthContraint?.constant = 20 } else { - errorIconWidthContraint?.constant = 0 textField.accessibilityValue = nil } @@ -143,7 +141,6 @@ import UIKit //-------------------------------------------------- public var textFieldTrailingConstraint: NSLayoutConstraint? - public var errorIconWidthContraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Initializers diff --git a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift index 2908a90d..bad0492d 100644 --- a/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift +++ b/MVMCoreUI/Atomic/Molecules/Doughnut/DoughnutChart.swift @@ -17,7 +17,7 @@ open class DoughnutChart: View { public var doughnutLayer = CALayer() public var titleLabel = Label.createLabelBoldTitleLarge(true) public var subTitleLabel = Label.createLabelRegularMicro(true) - public var labelContainer = View() + public var labelContainer = MVMCoreUICommonViewsUtility.commonView() public static let heightConstant: CGFloat = 136 private var sizeObject = MFStyler.sizeObjectGeneric(forCurrentDevice: heightConstant)! From d755709daa37b4bd4b01ee0c125001e876a35923 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 8 Apr 2020 08:35:21 -0400 Subject: [PATCH 26/31] remove code for later change --- MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift b/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift index da46c26e..658af357 100644 --- a/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/TextFields/EntryField.swift @@ -57,12 +57,6 @@ import UIKit } } - public var accessoryInput: View? { - didSet { - - } - } - //-------------------------------------------------- // MARK: - Computed Properties //-------------------------------------------------- From fd31ca294bbb108f1b4b59eaf2017bb22f3b4718 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 8 Apr 2020 09:22:32 -0400 Subject: [PATCH 27/31] update made --- MVMCoreUI/Styles/Padding.swift | 16 ++++++++-------- MVMCoreUI/Styles/Styler.swift | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/MVMCoreUI/Styles/Padding.swift b/MVMCoreUI/Styles/Padding.swift index ca99d5dc..3ed0922e 100644 --- a/MVMCoreUI/Styles/Padding.swift +++ b/MVMCoreUI/Styles/Padding.swift @@ -11,7 +11,7 @@ import Foundation public struct Padding { - public static let One: CGFloat = 6 + public static let One: CGFloat = 8 public static let Two: CGFloat = 12 public static let Three: CGFloat = 18 public static let Four: CGFloat = 24 @@ -24,24 +24,24 @@ public struct Padding { public struct Default { public static let Standard: CGFloat = 24 - public static let HorizontalSpacing: CGFloat = 32 - public static let VerticalSpacing: CGFloat = 32 - public static let VerticalSpacing3: CGFloat = 24 + public static let HorizontalMarginSpacing: CGFloat = 32 + public static let LargeVerticalMarginSpacing: CGFloat = 32 + public static let VerticalMarginSpacing: CGFloat = 24 public static var horizontalPaddingForApplicationWidth: CGFloat { - return MFSizeObject(scalingStandardSize: HorizontalSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalSpacing + return MFSizeObject(scalingStandardSize: HorizontalMarginSpacing)?.getValueBasedOnApplicationWidth() ?? HorizontalMarginSpacing } public static var verticalPaddingForApplicationWidth: CGFloat { - return MFSizeObject(scalingStandardSize: VerticalSpacing)?.getValueBasedOnApplicationWidth() ?? VerticalSpacing + return MFSizeObject(scalingStandardSize: VerticalMarginSpacing)?.getValueBasedOnApplicationWidth() ?? VerticalMarginSpacing } public static func horizontalPaddingForSize(_ size: CGFloat) -> CGFloat { - return MFSizeObject(scalingStandardSize: HorizontalSpacing)?.getValueBased(onSize: size) ?? HorizontalSpacing + return MFSizeObject(scalingStandardSize: HorizontalMarginSpacing)?.getValueBased(onSize: size) ?? HorizontalMarginSpacing } public static func verticalPaddingForSize(_ size: CGFloat) -> CGFloat { - return MFSizeObject(scalingStandardSize: VerticalSpacing)?.getValueBased(onSize: size) ?? VerticalSpacing + return MFSizeObject(scalingStandardSize: VerticalMarginSpacing)?.getValueBased(onSize: size) ?? VerticalMarginSpacing } } } diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 75d0b9ee..e6675b1d 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -167,10 +167,10 @@ open class Styler { } /// Styles the provided label to the declared enum Font case. - public func styleLabel(_ label: UILabel, genericScaling: Bool = true) { + public func styleLabel(_ label: UILabel, textColor: UIColor = .mvmBlack, genericScaling: Bool = true) { label.font = getFont(genericScaling) - label.textColor = .black + label.textColor = textColor } } From de084aa89987af29d5a9db2b4b0fd1170a1eb1ec Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 8 Apr 2020 09:24:31 -0400 Subject: [PATCH 28/31] margin in styler --- MVMCoreUI/Styles/Styler.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index e6675b1d..e5ac19b7 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -197,8 +197,8 @@ open class Styler { open class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat?, horizontal: Bool = true, vertical: Bool = false) { - var horizontalPadding: CGFloat = Padding.Default.HorizontalSpacing - let verticalPadding: CGFloat = vertical ? Padding.Default.VerticalSpacing3 : 0 + var horizontalPadding: CGFloat = Padding.Default.HorizontalMarginSpacing + let verticalPadding: CGFloat = vertical ? Padding.Default.VerticalMarginSpacing : 0 if let size = size { horizontalPadding = horizontal ? Padding.Default.horizontalPaddingForSize(size) : 0 From 8b957b1d4969ea0c96a600cb288aed2a966efedd Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 8 Apr 2020 10:10:39 -0400 Subject: [PATCH 29/31] padding updates --- MVMCoreUI/Styles/Padding.swift | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/MVMCoreUI/Styles/Padding.swift b/MVMCoreUI/Styles/Padding.swift index 3ed0922e..0dd9ff6e 100644 --- a/MVMCoreUI/Styles/Padding.swift +++ b/MVMCoreUI/Styles/Padding.swift @@ -9,20 +9,21 @@ import Foundation +/// Padding is a multiple based on the number 4. public struct Padding { - public static let One: CGFloat = 8 - public static let Two: CGFloat = 12 - public static let Three: CGFloat = 18 - public static let Four: CGFloat = 24 - public static let Five: CGFloat = 30 - public static let Six: CGFloat = 36 - public static let Seven: CGFloat = 42 - public static let Eight: CGFloat = 48 - public static let Nine: CGFloat = 54 - public static let Ten: CGFloat = 60 + public static let OneHalf: CGFloat = 2 + public static let One: CGFloat = 4 + public static let Two: CGFloat = 8 + public static let Three: CGFloat = 12 + public static let Four: CGFloat = 16 + public static let Five: CGFloat = 24 + public static let Eight: CGFloat = 32 + public static let Ten: CGFloat = 40 + public static let Twelve: CGFloat = 48 + public static let Eighteen: CGFloat = 72 - public struct Default { + public struct Component { public static let Standard: CGFloat = 24 public static let HorizontalMarginSpacing: CGFloat = 32 public static let LargeVerticalMarginSpacing: CGFloat = 32 From c52337a08beb9e795b03f7f92ceaa0d34f10a1d3 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 8 Apr 2020 10:28:14 -0400 Subject: [PATCH 30/31] name change --- MVMCoreUI/Styles/Styler.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index e5ac19b7..96bd558c 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -197,11 +197,11 @@ open class Styler { open class func setDefaultMarginsFor(_ view: UIView?, size: CGFloat?, horizontal: Bool = true, vertical: Bool = false) { - var horizontalPadding: CGFloat = Padding.Default.HorizontalMarginSpacing - let verticalPadding: CGFloat = vertical ? Padding.Default.VerticalMarginSpacing : 0 + var horizontalPadding: CGFloat = Padding.Component.HorizontalMarginSpacing + let verticalPadding: CGFloat = vertical ? Padding.Component.VerticalMarginSpacing : 0 if let size = size { - horizontalPadding = horizontal ? Padding.Default.horizontalPaddingForSize(size) : 0 + horizontalPadding = horizontal ? Padding.Component.horizontalPaddingForSize(size) : 0 } DispatchQueue.main.async { @@ -215,7 +215,7 @@ open class Styler { open class func setMarginsFor(_ view: UIView?, size: CGFloat, defaultHorizontal horizontal: Bool, top: CGFloat, bottom: CGFloat) { - let horizontalPadding: CGFloat = horizontal ? Padding.Default.horizontalPaddingForSize(size) : 0 + let horizontalPadding: CGFloat = horizontal ? Padding.Component.horizontalPaddingForSize(size) : 0 DispatchQueue.main.async { MVMCoreUIUtility.setMarginsFor(view, From 76d4a3975780b2a945502beae04a879efcfb5bb0 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 9 Apr 2020 10:25:02 -0400 Subject: [PATCH 31/31] change for git --- MVMCoreUI/Styles/Styler.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Styles/Styler.swift b/MVMCoreUI/Styles/Styler.swift index 96bd558c..b5d6627c 100644 --- a/MVMCoreUI/Styles/Styler.swift +++ b/MVMCoreUI/Styles/Styler.swift @@ -213,9 +213,9 @@ open class Styler { } } - open class func setMarginsFor(_ view: UIView?, size: CGFloat, defaultHorizontal horizontal: Bool, top: CGFloat, bottom: CGFloat) { + open class func setMarginsFor(_ view: UIView?, size: CGFloat, horizontal: CGFloat?, top: CGFloat, bottom: CGFloat) { - let horizontalPadding: CGFloat = horizontal ? Padding.Component.horizontalPaddingForSize(size) : 0 + let horizontalPadding: CGFloat = horizontal ?? Padding.Component.horizontalPaddingForSize(size) DispatchQueue.main.async { MVMCoreUIUtility.setMarginsFor(view,