From 63556707bc66928585b966a3287932b9aac2fd5f Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 27 Nov 2019 13:49:01 -0500 Subject: [PATCH] temporary dropdown molecule label reuse font fixes --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++ MVMCoreUI/Atoms/TextFields/MFTextField.h | 1 + MVMCoreUI/Atoms/TextFields/MFTextField.m | 1 + MVMCoreUI/Atoms/TextFields/MFTextField.xib | 9 +- MVMCoreUI/Atoms/Views/DropDown.swift | 55 ++++++++++++ MVMCoreUI/Atoms/Views/Label.swift | 28 +++--- MVMCoreUI/Atoms/Views/ViewConstrainingView.m | 1 - .../Items/DropDownFilterTableViewCell.swift | 70 +++++++++++++++ .../MVMCoreUIMoleculeMappingObject.m | 10 ++- MVMCoreUI/Styles/MFStyler.h | 10 +++ MVMCoreUI/Styles/MFStyler.m | 90 +++++++++++++------ 11 files changed, 234 insertions(+), 49 deletions(-) create mode 100644 MVMCoreUI/Atoms/Views/DropDown.swift create mode 100644 MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 391e20f5..515e24ee 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -50,6 +50,8 @@ D260D7B122D65BDD007E7233 /* MVMCoreUIPageControl.h in Headers */ = {isa = PBXBuildFile; fileRef = D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */; settings = {ATTRIBUTES = (Public, ); }; }; D260D7B222D65BDD007E7233 /* MVMCoreUIPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */; }; D260D7B622D68514007E7233 /* MVMCoreUIPagingProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; + D268C70E238C22D7007F2C1C /* DropDownFilterTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D268C70D238C22D7007F2C1C /* DropDownFilterTableViewCell.swift */; }; + D268C712238D6699007F2C1C /* DropDown.swift in Sources */ = {isa = PBXBuildFile; fileRef = D268C711238D6699007F2C1C /* DropDown.swift */; }; D274CA332236A78900B01B62 /* StandardFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D274CA322236A78900B01B62 /* StandardFooterView.swift */; }; D2755D7B23689C7500485468 /* TableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2755D7A23689C7500485468 /* TableViewCell.swift */; }; D27CD40E2322EEAF00C1DC07 /* TabsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27CD40D2322EEAF00C1DC07 /* TabsTableViewCell.swift */; }; @@ -246,6 +248,8 @@ D260D7AF22D65BDD007E7233 /* MVMCoreUIPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIPageControl.h; sourceTree = ""; }; D260D7B022D65BDD007E7233 /* MVMCoreUIPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIPageControl.m; sourceTree = ""; }; D260D7B522D68509007E7233 /* MVMCoreUIPagingProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIPagingProtocol.h; sourceTree = ""; }; + D268C70D238C22D7007F2C1C /* DropDownFilterTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DropDownFilterTableViewCell.swift; sourceTree = ""; }; + D268C711238D6699007F2C1C /* DropDown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDown.swift; sourceTree = ""; }; D274CA322236A78900B01B62 /* StandardFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardFooterView.swift; sourceTree = ""; }; D2755D7A23689C7500485468 /* TableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewCell.swift; sourceTree = ""; }; D27CD40D2322EEAF00C1DC07 /* TabsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsTableViewCell.swift; sourceTree = ""; }; @@ -509,6 +513,7 @@ D2A6390422CBCE160052ED1F /* MoleculeCollectionViewCell.swift */, D224799A231965AD003FCCF9 /* AccordionMoleculeTableViewCell.swift */, D27CD40D2322EEAF00C1DC07 /* TabsTableViewCell.swift */, + D268C70D238C22D7007F2C1C /* DropDownFilterTableViewCell.swift */, ); path = Items; sourceTree = ""; @@ -752,6 +757,7 @@ D29DF2AD21E7B3A4003B2FB9 /* MFTextView.h */, D29DF2AB21E7B3A4003B2FB9 /* MFTextView.m */, D29DF2AC21E7B3A4003B2FB9 /* MFTextView.xib */, + D268C711238D6699007F2C1C /* DropDown.swift */, D29DF2B121E7B76C003B2FB9 /* MFLoadingSpinner.h */, D29DF2B221E7B76D003B2FB9 /* MFLoadingSpinner.m */, D29DF32321ED0DA2003B2FB9 /* TextButtonView.h */, @@ -1071,6 +1077,7 @@ D224799B231965AD003FCCF9 /* AccordionMoleculeTableViewCell.swift in Sources */, D22D1F1F220343560077CEC0 /* MVMCoreUICheckMarkView.m in Sources */, 01004F3022721C3800991ECC /* RadioButton.swift in Sources */, + D268C70E238C22D7007F2C1C /* DropDownFilterTableViewCell.swift in Sources */, D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */, D29DF11721E6805F003B2FB9 /* UIColor+MFConvenience.m in Sources */, D29DF25321E6A177003B2FB9 /* MFDigitTextField.m in Sources */, @@ -1154,6 +1161,7 @@ D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */, + D268C712238D6699007F2C1C /* DropDown.swift in Sources */, 0A41BA6E2344FCD400D4C0BC /* CATransaction+Extension.swift in Sources */, D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */, D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */, diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.h b/MVMCoreUI/Atoms/TextFields/MFTextField.h index 8ccbe22e..aa3ab573 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.h +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.h @@ -74,6 +74,7 @@ //default error message @property (nullable, strong, nonatomic) NSString *errMessage; +@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *errorHeightConstraint; @property (nullable, copy, nonatomic) void (^editCompleteAction)(NSString * _Nullable text); diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.m b/MVMCoreUI/Atoms/TextFields/MFTextField.m index cfef9090..fec796bf 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.m +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.m @@ -558,6 +558,7 @@ #pragma mark - MVMCoreUIMoleculeViewProtocol - (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData { + [super setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) { [FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol]; FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:delegateObject.formValidationProtocol]; diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.xib b/MVMCoreUI/Atoms/TextFields/MFTextField.xib index cb9821f1..c11beb5c 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.xib +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.xib @@ -1,11 +1,9 @@ - - - - + + - + @@ -15,6 +13,7 @@ + diff --git a/MVMCoreUI/Atoms/Views/DropDown.swift b/MVMCoreUI/Atoms/Views/DropDown.swift new file mode 100644 index 00000000..88d0a2c2 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/DropDown.swift @@ -0,0 +1,55 @@ +// +// DropDown.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 11/26/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class DropDown: MFTextField { + let picker = MVMCoreUICommonViewsUtility.commonPickerView()! + + public override func getNib() -> UINib? { + return UINib(nibName: String(describing: MFTextField.self), bundle: MVMCoreUIUtility.bundleForMVMCoreUI()) + } + + public override func setupView() { + super.setupView() + dropDownCarrotWidth?.isActive = false + errorHeightConstraint?.constant = 0 + } + + override public func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + guard let textField = textField, textField.inputView == nil else { return } + picker.delegate = self + picker.dataSource = self + picker.tag = textField.tag + textField.inputView = picker + picker.reloadAllComponents() + MVMCoreUICommonViewsUtility.addDismissToolbar(textField, delegate: delegateObject?.uiTextFieldDelegate) + textField.text = json?.stringWithChainOfKeysOrIndexes([KeyValue,picker.selectedRow(inComponent: 0)]) + } +} + +extension DropDown: UIPickerViewDelegate { + public func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return json?.stringWithChainOfKeysOrIndexes([KeyValue,row]) + } + + public func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + textField?.text = json?.stringWithChainOfKeysOrIndexes([KeyValue,row]) + } +} + +extension DropDown: UIPickerViewDataSource { + public func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + + public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return json?.optionalArrayForKey(KeyValue)?.count ?? 0 + } +} diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 8474d74a..b2cc4f56 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -212,9 +212,12 @@ public typealias ActionBlock = () -> () } @objc public static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) { - guard let label = label else { return } - label.attributedText = nil + + // Some properties can only be set on Label. + // Label fonts should not be scaled because it will be scaled in updateView. + let mvmLabel = label as? Label + label.text = json?.optionalStringForKey(KeyText) setLabel(label, withHTML: json?.optionalStringForKey("html")) @@ -230,9 +233,7 @@ public typealias ActionBlock = () -> () } } - if let wholeViewIsClickable = json?.boolForKey("makeWholeViewClickable") { - (label as? Label)?.makeWholeViewClickable = wholeViewIsClickable - } + mvmLabel?.makeWholeViewClickable = json?.boolForKey("makeWholeViewClickable") ?? false if let backgroundColorHex = json?.optionalStringForKey(KeyBackgroundColor), !backgroundColorHex.isEmpty { label.backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) @@ -241,12 +242,12 @@ public typealias ActionBlock = () -> () label.accessibilityLabel = json?.optionalStringForKey("accessibilityText") if let fontStyle = json?.optionalStringForKey("fontStyle") { - MFStyler.styleLabel(label, withStyle: fontStyle) + MFStyler.styleLabel(label, withStyle: fontStyle, genericScaling: mvmLabel == nil) } else { let fontSize = json?["fontSize"] as? CGFloat if let fontName = json?.optionalStringForKey("fontName") { - label.font = MFFonts.mfFont(withName: fontName, size: fontSize ?? label.font.pointSize) + label.font = MFFonts.mfFont(withName: fontName, size: fontSize ?? mvmLabel?.standardFontSize ?? label.font.pointSize) } else if let fontSize = fontSize { label.font = label.font.withSize(fontSize) } @@ -256,8 +257,8 @@ public typealias ActionBlock = () -> () label.textColor = UIColor.mfGet(forHex: textColorHex) } - if let attributes = json?.arrayForKey("attributes"), let labelText = label.text { - let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font as UIFont, + if let attributes = json?.optionalArrayForKey("attributes"), let labelText = label.text { + let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: mvmLabel?.font.withSize(mvmLabel!.standardFontSize) ?? label.font as UIFont, NSAttributedString.Key.foregroundColor: label.textColor as UIColor]) for case let attribute as [String: Any] in attributes { guard let attributeType = attribute.optionalStringForKey(KeyType), @@ -298,7 +299,7 @@ public typealias ActionBlock = () -> () case "font": if let fontStyle = attribute.optionalStringForKey("style") { - let styles = MFStyler.styleGetAttributedString("0", withStyle: fontStyle) + let styles = MFStyler.styleGetAttributedString("0", withStyle: fontStyle, genericScaling: mvmLabel == nil) attributedString.removeAttribute(.font, range: range) attributedString.removeAttribute(.foregroundColor, range: range) attributedString.addAttributes(styles.attributes(at: 0, effectiveRange: nil), range: range) @@ -307,7 +308,7 @@ public typealias ActionBlock = () -> () var font: UIFont? if let fontName = attribute.optionalStringForKey("name") { - font = MFFonts.mfFont(withName: fontName, size: fontSize ?? label.font.pointSize) + font = MFFonts.mfFont(withName: fontName, size: fontSize ?? mvmLabel?.standardFontSize ?? label.font.pointSize) } else if let fontSize = fontSize { font = label.font.withSize(fontSize) } @@ -330,6 +331,7 @@ public typealias ActionBlock = () -> () } } label.attributedText = attributedString + mvmLabel?.originalAttributedString = attributedString } } @@ -419,7 +421,7 @@ public typealias ActionBlock = () -> () if let floatScale = scaleSize?.floatValue { updateView(CGFloat(floatScale)) } else { - updateView(MVMCoreUISplitViewController.getApplicationViewWidth()) + updateView(MVMCoreUIUtility.getWidth()) } } else { standardFontSize = 0 @@ -581,8 +583,6 @@ extension Label { @objc public func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { clauses = [] Label.setUILabel(self, withJSON: json, delegate: delegateObject, additionalData: additionalData) - originalAttributedString = attributedText - hero = json?["hero"] as? Int } diff --git a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m index 66a3a83d..f7aaf7f6 100644 --- a/MVMCoreUI/Atoms/Views/ViewConstrainingView.m +++ b/MVMCoreUI/Atoms/Views/ViewConstrainingView.m @@ -357,7 +357,6 @@ if (!self.constrainedView) { [super setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; } - [self.molecule setWithJSON:json delegateObject:delegateObject additionalData:additionalData]; if (self.shouldSetupMoleculeFromJSON) { NSDictionary *moleculeJSON = [json dict:KeyMolecule]; if (self.molecule) { diff --git a/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift new file mode 100644 index 00000000..518e3b51 --- /dev/null +++ b/MVMCoreUI/Molecules/Items/DropDownFilterTableViewCell.swift @@ -0,0 +1,70 @@ +// +// DropDownFilterTableViewCell.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 9/6/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class DropDownFilterTableViewCell: TableViewCell { + let dropDown = DropDown(forDropDownWithBothDelegates: nil) + var delegateObject: MVMCoreUIDelegateObject? + var previousIndex = NSNotFound + var dropDownSelectionObservation: NSKeyValueObservation? + + // MARK: - MFViewProtocol + override public func setupView() { + super.setupView() + guard let dropDown = dropDown, dropDown.superview == nil else { + return + } + bottomMarginPadding = 0 + + dropDown.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(dropDown) + + NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: dropDown, useMargins: true).values)) + + #warning("Once we have the state manager, we will need to change this logic to only add or remove on user selection...Want to avoid re-use crashes from array size differences") + dropDownSelectionObservation = observe( + \.dropDown?.textField?.text, + options: [.old, .new] + ) { [weak self] object, change in + guard change.newValue != change.oldValue, let self = self, + let options = self.dropDown?.json?.optionalArrayForKey(KeyValue) as? [NSString], + let index = options.firstIndex(of: change.newValue!! as NSString), + let moleculesArrays = self.json?.arrayForKey(KeyMolecules) as? [[[AnyHashable: Any]]] else { return } + + if self.previousIndex != NSNotFound { + let previousMolecules = moleculesArrays[self.previousIndex] + self.delegateObject?.moleculeDelegate?.removeMolecules?(previousMolecules, sender: self, animation: .fade) + } + let molecules = moleculesArrays[index] + self.delegateObject?.moleculeDelegate?.addMolecules?(molecules, sender: self, animation: .fade) + self.previousIndex = index + } + } + + public override func updateView(_ size: CGFloat) { + super.updateView(size) + dropDown?.updateView(size) + } + + // MARK: - MoleculeDelegateProtocol + public override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { + bottomSeparatorView?.style = .none + self.delegateObject = delegateObject + super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) + dropDown?.mfTextFieldDelegate = delegateObject?.uiTextFieldDelegate as? MFTextFieldDelegate + dropDown?.uiTextFieldDelegate = delegateObject?.uiTextFieldDelegate + dropDown?.setWithJSON(json?.optionalDictionaryForKey("dropDown"), delegateObject: delegateObject, additionalData: additionalData) + } + + public override func reset() { + super.reset() + bottomMarginPadding = 0 + bottomSeparatorView?.style = .none + } +} diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m index 4303dc55..51a07225 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject.m @@ -35,10 +35,11 @@ @"footer": StandardFooterView.class, @"caretView": CaretView.class, @"caretButton": CaretButton.class, - @"textField" : MFTextField.class, - @"digitTextField" : MFDigitTextField.class, - @"checkbox" : Checkbox.class, - @"checkboxWithLabel" : CheckboxWithLabelView.class, + @"textField": MFTextField.class, + @"dropDown": DropDown.class, + @"digitTextField": MFDigitTextField.class, + @"checkbox": Checkbox.class, + @"checkboxWithLabel": CheckboxWithLabelView.class, @"cornerLabels" : CornerLabels.class, @"progressbar": ProgressBar.class, @"circleProgress": GraphView.class, @@ -63,6 +64,7 @@ @"headlineBodyTextButton": HeadlineBodyTextButton.class, @"headlineBodyTextButtonSwitch": HeadlineBodyTextButtonSwitch.class, @"tabsListItem": TabsTableViewCell.class, + @"dropDownListItem": DropDownFilterTableViewCell.class, @"headlineBodyButton": HeadlineBodyButton.class, @"eyebrowHeadlineBodyLink": EyebrowHeadlineBodyLink.class } mutableCopy]; diff --git a/MVMCoreUI/Styles/MFStyler.h b/MVMCoreUI/Styles/MFStyler.h index 5b73c8e2..bdef57ba 100644 --- a/MVMCoreUI/Styles/MFStyler.h +++ b/MVMCoreUI/Styles/MFStyler.h @@ -210,6 +210,7 @@ B3 -> Legal /// Will style the label based on the string. Accepted values, H1, H2, H3, H32, B1, B2, B3, B20 + (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style; ++ (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling; + (void)styleLabelH1:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling; + (void)styleLabelH1:(nonnull UILabel *)label; @@ -258,6 +259,7 @@ B3 -> Legal /// Will style the string based on the string. Accepted values, H1, H2, H3, H32, B1, B2, B3, B20 + (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string withStyle:(nullable NSString *)style; ++ (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling; + (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string font:(nonnull UIFont *)font color:(nonnull UIColor *)color; + (nonnull NSAttributedString *)styleGetH1AttributedString:(nullable NSString *)string; @@ -266,6 +268,14 @@ B3 -> Legal + (nonnull NSAttributedString *)styleGetB1AttributedString:(nullable NSString *)string; + (nonnull NSAttributedString *)styleGetB2AttributedString:(nullable NSString *)string; + (nonnull NSAttributedString *)styleGetB3AttributedString:(nullable NSString *)string; ++ (nonnull NSAttributedString *)styleGetH1AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling; ++ (nonnull NSAttributedString *)styleGetH2AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling; ++ (nonnull NSAttributedString *)styleGetH3AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling; ++ (nonnull NSAttributedString *)styleGetH32AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling; ++ (nonnull NSAttributedString *)styleGetB1AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling; ++ (nonnull NSAttributedString *)styleGetB2AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling; ++ (nonnull NSAttributedString *)styleGetB3AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling; ++ (nonnull NSAttributedString *)styleGetB20AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling; + (nonnull NSAttributedString *)styleGetDisabledB2AttributedString:(nullable NSString *)string; + (nonnull NSAttributedString *)styleGetDisabledB1AttributedString:(nullable NSString *)string; diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index 18246f7f..c3dc8946 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -516,26 +516,30 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; #pragma mark - 2.0 Styles -+ (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style { ++ (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling { if ([style isEqualToString:@"H1"]) { - [self styleLabelH1:label]; + [self styleLabelH1:label genericScaling:genericScaling]; } else if ([style isEqualToString:@"H2"]) { - [self styleLabelH2:label]; + [self styleLabelH2:label genericScaling:genericScaling]; } else if ([style isEqualToString:@"H3"]) { - [self styleLabelH3:label]; + [self styleLabelH3:label genericScaling:genericScaling]; } else if ([style isEqualToString:@"H32"]) { - [self styleLabelH32:label]; + [self styleLabelH32:label genericScaling:genericScaling]; } else if ([style isEqualToString:@"B1"]) { - [self styleLabelB1:label]; + [self styleLabelB1:label genericScaling:genericScaling]; } else if ([style isEqualToString:@"B3"]) { - [self styleLabelB3:label]; + [self styleLabelB3:label genericScaling:genericScaling]; } else if ([style isEqualToString:@"B20"]) { - [self styleLabelB20:label]; + [self styleLabelB20:label genericScaling:genericScaling]; } else { - [self styleLabelB2:label]; + [self styleLabelB2:label genericScaling:genericScaling]; } } ++ (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style { + [self styleLabel:label withStyle:style genericScaling:YES]; +} + + (void)styleLabelH1:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling { label.font = [MFStyler fontH1:genericScaling]; label.textColor = [UIColor blackColor]; @@ -656,22 +660,26 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; #pragma mark - Attributed Strings + (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string withStyle:(nullable NSString *)style { + return [self styleGetAttributedString:string withStyle:style genericScaling:YES]; +} + ++ (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string withStyle:(nullable NSString *)style genericScaling:(BOOL)genericScaling { if ([style isEqualToString:@"H1"]) { - return [self styleGetH1AttributedString:string]; + return [self styleGetH1AttributedString:string genericScaling:genericScaling]; } else if ([style isEqualToString:@"H2"]) { - return [self styleGetH2AttributedString:string]; + return [self styleGetH2AttributedString:string genericScaling:genericScaling]; } else if ([style isEqualToString:@"H3"]) { - return [self styleGetH3AttributedString:string]; + return [self styleGetH3AttributedString:string genericScaling:genericScaling]; } else if ([style isEqualToString:@"H32"]) { - return [self styleGetH32AttributedString:string]; + return [self styleGetH32AttributedString:string genericScaling:genericScaling]; } else if ([style isEqualToString:@"B1"]) { - return [self styleGetB1AttributedString:string]; + return [self styleGetB1AttributedString:string genericScaling:genericScaling]; } else if ([style isEqualToString:@"B3"]) { - return [self styleGetB3AttributedString:string]; + return [self styleGetB3AttributedString:string genericScaling:genericScaling]; } else if ([style isEqualToString:@"B20"]) { - return [self styleGetB20AttributedString:string]; + return [self styleGetB20AttributedString:string genericScaling:genericScaling]; } else { - return [self styleGetB2AttributedString:string]; + return [self styleGetB2AttributedString:string genericScaling:genericScaling]; } } @@ -690,35 +698,67 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; } + (nonnull NSAttributedString *)styleGetH1AttributedString:(nullable NSString *)string { - return [MFStyler styleGetAttributedString:string font:[MFStyler fontH1] color:[UIColor blackColor]]; + return [MFStyler styleGetH1AttributedString:string genericScaling:YES]; +} + ++ (nonnull NSAttributedString *)styleGetH1AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling { + return [MFStyler styleGetAttributedString:string font:[MFStyler fontH1:genericScaling] color:[UIColor blackColor]]; } + (nonnull NSAttributedString *)styleGetH2AttributedString:(nullable NSString *)string { - return [MFStyler styleGetAttributedString:string font:[MFStyler fontH2] color:[UIColor blackColor]]; + return [MFStyler styleGetH2AttributedString:string genericScaling:YES]; +} + ++ (nonnull NSAttributedString *)styleGetH2AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling { + return [MFStyler styleGetAttributedString:string font:[MFStyler fontH2:genericScaling] color:[UIColor blackColor]]; } + (nonnull NSAttributedString *)styleGetH3AttributedString:(nullable NSString *)string { - return [MFStyler styleGetAttributedString:string font:[MFStyler fontH3] color:[UIColor blackColor]]; + return [MFStyler styleGetH3AttributedString:string genericScaling:YES]; +} + ++ (nonnull NSAttributedString *)styleGetH3AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling { + return [MFStyler styleGetAttributedString:string font:[MFStyler fontH3:genericScaling] color:[UIColor blackColor]]; } + (nonnull NSAttributedString *)styleGetH32AttributedString:(nullable NSString *)string { - return [MFStyler styleGetAttributedString:string font:[MFStyler fontH32] color:[UIColor blackColor]]; + return [MFStyler styleGetH32AttributedString:string genericScaling:YES]; +} + ++ (nonnull NSAttributedString *)styleGetH32AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling { + return [MFStyler styleGetAttributedString:string font:[MFStyler fontH32:genericScaling] color:[UIColor blackColor]]; } + (nonnull NSAttributedString *)styleGetB1AttributedString:(nullable NSString *)string { - return [MFStyler styleGetAttributedString:string font:[MFStyler fontB1] color:[UIColor blackColor]]; + return [MFStyler styleGetB1AttributedString:string genericScaling:YES]; +} + ++ (nonnull NSAttributedString *)styleGetB1AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling { + return [MFStyler styleGetAttributedString:string font:[MFStyler fontB1:genericScaling] color:[UIColor blackColor]]; } + (nonnull NSAttributedString *)styleGetB2AttributedString:(nullable NSString *)string { - return [MFStyler styleGetAttributedString:string font:[MFStyler fontB2] color:[UIColor blackColor]]; + return [MFStyler styleGetB2AttributedString:string genericScaling:YES]; +} + ++ (nonnull NSAttributedString *)styleGetB2AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling { + return [MFStyler styleGetAttributedString:string font:[MFStyler fontB2:genericScaling] color:[UIColor blackColor]]; } + (nonnull NSAttributedString *)styleGetB3AttributedString:(nullable NSString *)string { - return [MFStyler styleGetAttributedString:string font:[MFStyler fontB3] color:[UIColor mfBattleshipGrey]]; + return [MFStyler styleGetB3AttributedString:string genericScaling:YES]; +} + ++ (nonnull NSAttributedString *)styleGetB3AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling { + return [MFStyler styleGetAttributedString:string font:[MFStyler fontB3:genericScaling] color:[UIColor mfBattleshipGrey]]; } + (nonnull NSAttributedString *)styleGetB20AttributedString:(nullable NSString *)string { - return [MFStyler styleGetAttributedString:string font:[MFStyler fontB20] color:[UIColor blackColor]]; + return [MFStyler styleGetB20AttributedString:string genericScaling:YES]; +} + ++ (nonnull NSAttributedString *)styleGetB20AttributedString:(nullable NSString *)string genericScaling:(BOOL)genericScaling { + return [MFStyler styleGetAttributedString:string font:[MFStyler fontB20:genericScaling] color:[UIColor blackColor]]; } + (nonnull NSAttributedString *)styleGetDisabledB1AttributedString:(nullable NSString *)string {