diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index e6e0c46c..a5ba4be0 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -147,22 +147,26 @@ import MVMCore setLabel(label, withHTML: json?.optionalStringForKey("html")) - if let textColorHex = json?.optionalStringForKey(KeyTextColor), !textColorHex.isEmpty { - label.textColor = UIColor.mfGet(forHex: textColorHex) - } - if let backgroundColorHex = json?.optionalStringForKey(KeyBackgroundColor), !backgroundColorHex.isEmpty { label.backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) } label.accessibilityLabel = json?.optionalStringForKey("accessibilityText") - let fontSize = json?["fontSize"] as? CGFloat + if let fontStyle = json?.optionalStringForKey("fontStyle") { + MFStyler.styleLabel(label, withStyle: fontStyle) + } else { + let fontSize = json?["fontSize"] as? CGFloat + + if let fontName = json?.optionalStringForKey("fontName") { + label.font = MFFonts.mfFont(withName: fontName, size: fontSize ?? label.font.pointSize) + } else if let fontSize = fontSize { + label.font = label.font.withSize(fontSize) + } + } - if let fontName = json?.optionalStringForKey("fontName") { - label.font = MFFonts.mfFont(withName: fontName, size: fontSize ?? label.font.pointSize) - } else if let fontSize = fontSize { - label.font = label.font.withSize(fontSize) + if let textColorHex = json?.optionalStringForKey(KeyTextColor), !textColorHex.isEmpty { + label.textColor = UIColor.mfGet(forHex: textColorHex) } if let attributes = json?.arrayForKey("attributes"), let labelText = label.text { @@ -190,18 +194,25 @@ import MVMCore attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range) } case "font": - let fontSize = attribute["size"] as? CGFloat - var font: UIFont? - - if let fontName = attribute.optionalStringForKey("name") { - font = MFFonts.mfFont(withName: fontName, size: fontSize ?? label.font.pointSize) - } else if let fontSize = fontSize { - font = label.font.withSize(fontSize) - } - - if let font = font { + if let fontStyle = attribute.optionalStringForKey("style") { + let styles = MFStyler.styleGetAttributedString("0", withStyle: fontStyle) attributedString.removeAttribute(.font, range: range) - attributedString.addAttribute(.font, value: font, range: range) + attributedString.removeAttribute(.foregroundColor, range: range) + attributedString.addAttributes(styles.attributes(at: 0, effectiveRange: nil), range: range) + } else { + let fontSize = attribute["size"] as? CGFloat + var font: UIFont? + + if let fontName = attribute.optionalStringForKey("name") { + font = MFFonts.mfFont(withName: fontName, size: fontSize ?? label.font.pointSize) + } else if let fontSize = fontSize { + font = label.font.withSize(fontSize) + } + + if let font = font { + attributedString.removeAttribute(.font, range: range) + attributedString.addAttribute(.font, value: font, range: range) + } } default: continue @@ -308,6 +319,7 @@ import MVMCore } public func setAsMolecule() { + styleB2(true) } public func needsToBeConstrained() -> Bool { diff --git a/MVMCoreUI/Molecules/MoleculeStackView.swift b/MVMCoreUI/Molecules/MoleculeStackView.swift index efd4752e..0f539827 100644 --- a/MVMCoreUI/Molecules/MoleculeStackView.swift +++ b/MVMCoreUI/Molecules/MoleculeStackView.swift @@ -119,6 +119,14 @@ public class MoleculeStackView: ViewConstrainingView { } // MARK: - MVMCoreUIMoleculeViewProtocol + public override func reset() { + for item in items { + if let view = item.view as? MVMCoreUIMoleculeViewProtocol { + view.reset?() + } + } + } + open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) clear() diff --git a/MVMCoreUI/Molecules/StandardHeaderView.swift b/MVMCoreUI/Molecules/StandardHeaderView.swift index 26ce345b..2391f062 100644 --- a/MVMCoreUI/Molecules/StandardHeaderView.swift +++ b/MVMCoreUI/Molecules/StandardHeaderView.swift @@ -68,7 +68,6 @@ public class StandardHeaderView: ViewConstrainingView { if let separatorView = SeparatorView.separatorAdd(to: self, position: SeparatorPositionBot, withHorizontalPadding: 0) { separatorView.setAsHeavy() - separatorView.isHidden = true addSubview(separatorView) self.separatorView = separatorView } diff --git a/MVMCoreUI/Styles/MFStyler.h b/MVMCoreUI/Styles/MFStyler.h index b8c80752..bda6c112 100644 --- a/MVMCoreUI/Styles/MFStyler.h +++ b/MVMCoreUI/Styles/MFStyler.h @@ -205,6 +205,9 @@ B3 -> Legal #pragma mark - 2.0 styles +/// 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)styleLabelH1:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling; + (void)styleLabelH1:(nonnull UILabel *)label; @@ -250,6 +253,9 @@ B3 -> Legal #pragma mark - Attributed Strings +/// 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 font:(nonnull UIFont *)font color:(nonnull UIColor *)color; + (nonnull NSAttributedString *)styleGetH1AttributedString:(nullable NSString *)string; + (nonnull NSAttributedString *)styleGetH2AttributedString:(nullable NSString *)string; diff --git a/MVMCoreUI/Styles/MFStyler.m b/MVMCoreUI/Styles/MFStyler.m index 4f27b2be..dc9288d8 100644 --- a/MVMCoreUI/Styles/MFStyler.m +++ b/MVMCoreUI/Styles/MFStyler.m @@ -511,6 +511,26 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; #pragma mark - 2.0 Styles ++ (void)styleLabel:(nonnull UILabel *)label withStyle:(nullable NSString *)style { + if ([style isEqualToString:@"H1"]) { + [self styleLabelH1:label]; + } else if ([style isEqualToString:@"H2"]) { + [self styleLabelH2:label]; + } else if ([style isEqualToString:@"H3"]) { + [self styleLabelH3:label]; + } else if ([style isEqualToString:@"H32"]) { + [self styleLabelH32:label]; + } else if ([style isEqualToString:@"B1"]) { + [self styleLabelB1:label]; + } else if ([style isEqualToString:@"B3"]) { + [self styleLabelB3:label]; + } else if ([style isEqualToString:@"B20"]) { + [self styleLabelB20:label]; + } else { + [self styleLabelB2:label]; + } +} + + (void)styleLabelH1:(nonnull UILabel *)label genericScaling:(BOOL)genericScaling { label.font = [MFStyler fontH1:genericScaling]; label.textColor = [UIColor blackColor]; @@ -630,6 +650,26 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; #pragma mark - Attributed Strings ++ (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string withStyle:(nullable NSString *)style { + if ([style isEqualToString:@"H1"]) { + return [self styleGetH1AttributedString:string]; + } else if ([style isEqualToString:@"H2"]) { + return [self styleGetH2AttributedString:string]; + } else if ([style isEqualToString:@"H3"]) { + return [self styleGetH3AttributedString:string]; + } else if ([style isEqualToString:@"H32"]) { + return [self styleGetH32AttributedString:string]; + } else if ([style isEqualToString:@"B1"]) { + return [self styleGetB1AttributedString:string]; + } else if ([style isEqualToString:@"B3"]) { + return [self styleGetB3AttributedString:string]; + } else if ([style isEqualToString:@"B20"]) { + return [self styleGetB20AttributedString:string]; + } else { + return [self styleGetB2AttributedString:string]; + } +} + + (nonnull NSAttributedString *)styleGetAttributedString:(nullable NSString *)string font:(nonnull UIFont *)font color:(nonnull UIColor *)color { NSAttributedString *attributedString = nil; if (![string isEqual:[NSNull null]] && string.length > 0) { @@ -656,6 +696,10 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; return [MFStyler styleGetAttributedString:string font:[MFStyler fontH3] color:[UIColor blackColor]]; } ++ (nonnull NSAttributedString *)styleGetH32AttributedString:(nullable NSString *)string { + return [MFStyler styleGetAttributedString:string font:[MFStyler fontH32] color:[UIColor blackColor]]; +} + + (nonnull NSAttributedString *)styleGetB1AttributedString:(nullable NSString *)string { return [MFStyler styleGetAttributedString:string font:[MFStyler fontB1] color:[UIColor blackColor]]; } @@ -668,6 +712,10 @@ CGFloat const LabelWithInternalButtonLineSpace = 2; return [MFStyler styleGetAttributedString:string font:[MFStyler fontB3] color:[UIColor mfBattleshipGrey]]; } ++ (nonnull NSAttributedString *)styleGetB20AttributedString:(nullable NSString *)string { + return [MFStyler styleGetAttributedString:string font:[MFStyler fontB20] color:[UIColor blackColor]]; +} + + (nonnull NSAttributedString *)styleGetDisabledB1AttributedString:(nullable NSString *)string { return [MFStyler styleGetAttributedString:string font:[MFStyler fontB1] color:[UIColor mfLighterGrayColor]]; } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 9f8b7707..490f2e1a 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -36,7 +36,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController { override open func viewForBottom() -> UIView { guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject() as? MVMCoreUIDelegateObject, constrainIfNeeded: true) else { - return viewForBottom() + return super.viewForBottom() } return molecule }