From 656652b962bd9d93048400b3937f86c7629f7252 Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Wed, 3 Apr 2019 09:35:26 -0400 Subject: [PATCH 01/19] Conversion of MFLabel to Label. WIP. --- MVMCoreUI.xcodeproj/project.pbxproj | 4 + MVMCoreUI/Atoms/Views/Label.swift | 388 ++++++++++++++++++++++++++++ 2 files changed, 392 insertions(+) create mode 100644 MVMCoreUI/Atoms/Views/Label.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 40733e65..a3219890 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -152,6 +152,7 @@ D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */; }; D2C5001D21F8EE67001DA659 /* LabelWithInternalButton.h in Headers */ = {isa = PBXBuildFile; fileRef = D2C5001B21F8EE66001DA659 /* LabelWithInternalButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; D2C5001E21F8EE67001DA659 /* LabelWithInternalButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C5001C21F8EE66001DA659 /* LabelWithInternalButton.m */; }; + DB891E832253FA8500022516 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB891E822253FA8500022516 /* Label.swift */; }; DBC4391822442197001AB423 /* CaretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391622442196001AB423 /* CaretView.swift */; }; DBC4391922442197001AB423 /* DashLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391722442197001AB423 /* DashLine.swift */; }; DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391A224421A0001AB423 /* CaretButton.swift */; }; @@ -307,6 +308,7 @@ D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIViewControllerMappingObject.m; sourceTree = ""; }; D2C5001B21F8EE66001DA659 /* LabelWithInternalButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LabelWithInternalButton.h; sourceTree = ""; }; D2C5001C21F8EE66001DA659 /* LabelWithInternalButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LabelWithInternalButton.m; sourceTree = ""; }; + DB891E822253FA8500022516 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; DBC4391622442196001AB423 /* CaretView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretView.swift; sourceTree = ""; }; DBC4391722442197001AB423 /* DashLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashLine.swift; sourceTree = ""; }; DBC4391A224421A0001AB423 /* CaretButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretButton.swift; sourceTree = ""; }; @@ -566,6 +568,7 @@ D22D1F19220341F50077CEC0 /* MVMCoreUICheckBox.m */, D22D1F44220496A30077CEC0 /* MVMCoreUISwitch.h */, D22D1F45220496A30077CEC0 /* MVMCoreUISwitch.m */, + DB891E822253FA8500022516 /* Label.swift */, ); path = Views; sourceTree = ""; @@ -867,6 +870,7 @@ D29DF2EF21ECEAE1003B2FB9 /* MFFonts.m in Sources */, D282AACB2243C61700C46919 /* ButtonView.swift in Sources */, D29DF2AE21E7B3A4003B2FB9 /* MFTextView.m in Sources */, + DB891E832253FA8500022516 /* Label.swift in Sources */, D29DF18121E69E50003B2FB9 /* MFView.m in Sources */, D29DF18321E69E54003B2FB9 /* SeparatorView.m in Sources */, D29DF17A21E69E1F003B2FB9 /* MFCustomButton.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift new file mode 100644 index 00000000..1f48273a --- /dev/null +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -0,0 +1,388 @@ +// +// Label.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 3/22/17. +// Converted by Christiano, Kevin on 4/2/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import MVMCore +import MVMCoreUI + + +class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { + //------------------------------------------------------ + // MARK: - Properties + //------------------------------------------------------ + + // Set this property if you want updateView to update the font based on this standard and the size passed in. + var standardFontSize: CGFloat = 0.0 + + // Set this to use a custom sizing object during updateView instead of the standard. + var sizeObject: MFSizeObject? + + private var scaleSize: NSNumber? + + // Used for scaling the font in updateView. + private var originalAttributedString: NSAttributedString? + + override var accessibilityTraits: UIAccessibilityTraits { + get { + return super.accessibilityTraits + } + set(accessibilityTraits) { + if accessibilityTraits.rawValue & UIAccessibilityTraits.header.rawValue != 0 { + let noHeaderTraits: UIAccessibilityTraits = UIAccessibilityTraits(rawValue: accessibilityTraits.rawValue - UIAccessibilityTraits.header.rawValue) + super.accessibilityTraits = noHeaderTraits + } else { + super.accessibilityTraits = accessibilityTraits + } + } + } + + var hasText: Bool { + return text.length > 0 || (attributedText?.length ?? 0) > 0 + } + + //------------------------------------------------------ + // MARK: - Initialization + //------------------------------------------------------ + + func setupView() { + backgroundColor = UIColor.clear + numberOfLines = 0 + lineBreakMode = NSLineBreakMode.byWordWrapping + translatesAutoresizingMaskIntoConstraints = false + } + + init() { + setupView() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + setupView() + } + + override init(frame: CGRect) { + super.init(frame: frame) + setupView() + } + + convenience init(standardFontSize size: CGFloat) { + self.init() + standardFontSize = size + } + + func updateView(_ size: CGFloat) { + + scaleSize = NSNumber(value: Float(size)) + + if originalAttributedString { + var attributedString = NSMutableAttributedString(attributedString: originalAttributedString) + attributedString.removeAttribute(.font, range: NSRange(location: 0, length: attributedString.length)) + originalAttributedString.enumerateAttribute(.font, in: NSRange(location: 0, length: originalAttributedString.length), options: [], using: { value, range, stop in + // Loop the original attributed string, resize the fonts. + let font: UIFont? = value?.withSize(MFStyler.sizeObjectGeneric(forCurrentDevice: value?.pointSize).getValueBased(onSize: size)) + attributedString.addAttribute(.font, value: font, range: range) + }) + attributedText = attributedString + } else if !fequal(standardFontSize, 0) { + var sizeObject: MFSizeObject? = self.sizeObject + if sizeObject == nil { + sizeObject = MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) + } + self.font = self.font.withSize(sizeObject?.getValueBased(onSize: size) ?? 0.0) + } + } + + func setFont(_ font: UIFont, scale: Bool) { + self.font = font + setScale(scale) + } + + func setScale(_ scale: Bool) { + if scale { + standardFontSize = font.pointSize + updateView((scaleSize ? CGFloat(scaleSize?.floatValue ?? 0) : MVMCoreUISplitViewController.getApplicationViewWidth())) + } else { + standardFontSize = 0 + } + } + + class func label() -> Label { + return Label(frame: CGRect.zero) + } + + class func commonLabelB2(_ scale: Bool) -> Label { + let label = Label.label() + label.styleB2(scale) + return label + } + + class func commonLabelBody(withSize size: CGFloat, scale: Bool) -> Label { + let label = Label.label() + label.styleBody(withSize: size, scale: scale) + return label + } + + class func commonLabelBodyBold(_ scale: Bool) -> Label { + let label = Label() + label.styleBodyBold(scale) + return label + } + + class func commonLabelBodyLighter(_ scale: Bool) -> Label { + let label = Label() + label.styleBodyLighter(scale) + return label + } + + class func commonLabelBodyLarge(_ scale: Bool) -> Label { + let label = Label() + label.styleBodyLarge(scale) + return label + } + + class func commonLabelH1(_ scale: Bool) -> Label { + let label = Label() + label.styleH1(scale) + return label + } + + class func commonLabelH2(_ scale: Bool) -> Label { + let label = Label() + label.styleH2(scale) + return label + } + + class func commonLabelHeadlineSmall(_ scale: Bool) -> Label { + let label = Label() + label.styleHeadlineSmall(scale) + return label + } + + class func commonLabelHeadline(withSize size: CGFloat, scale: Bool) -> Label { + let label = Label() + label.styleHeadline(withSize: size, scale: scale) + return label + } + + class func commonLabelHeadlineBlack(withSize size: CGFloat, scale: Bool) -> Label { + let label = Label() + label.styleHeadlineBlack(withSize: size, scale: scale) + return label + } + + class func commonLabelH3(_ scale: Bool) -> Label { + let label = Label() + label.styleH3(scale) + return label + } + + class func commonLabelSubheadBold(_ scale: Bool) -> Label { + let label = Label() + label.styleSubheadBold(scale) + return label + } + + class func commonLabelSubheadBoldLarge(_ scale: Bool) -> Label { + let label = Label() + label.styleSubheadBoldLarge(scale) + return label + } + + class func commonLabelB3(_ scale: Bool) -> Label { + let label = Label() + label.styleB3(scale) + return label + } + + class func commonLabelFeedMessage(_ scale: Bool) -> Label { + let label = Label() + label.styleFeedMessage(scale) + return label + } + + class func commonLabelFeedSubMessage(_ scale: Bool) -> Label { + let label = Label() + label.styleFeedSubMessage(scale) + return label + } + + class func commonLabelFeedHeadline(_ scale: Bool) -> Label { + let label = Label() + label.styleFeedHeadline(scale) + return label + } + + class func commonLabelFeedTitle(_ scale: Bool) -> Label { + let label = Label() + label.styleFeedTitle(scale) + return label + } + + class func commonLabelPlanCardTitle(_ scale: Bool) -> Label { + let label = Label() + label.stylePlanCardTitle(scale) + return label + } + + class func commonLabelB1(_ scale: Bool) -> Label { + let label = Label() + label.styleB1(scale) + return label + } + + class func commonLabelTopAlert(_ scale: Bool) -> Label { + let label = Label() + label.styleTopAlert(scale) + return label + } + + class func setLabel(_ label: UILabel?, withHTML html: String?) { + let data: Data? = html?.data(using: .utf8) + if data != nil { + var error: Error? = nil + if let data = data { + label?.attributedText = try? NSAttributedString(data: data, + options: [NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.html.rawValue as Any], + documentAttributes: nil) + } + if let labelError = error { + try? MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: labelError, location: "LabelHTMLParse")) + } + } + } + + class func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { + + // TODO: !!! + } + + func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { + Label.setUILabel(self, withJSON: json, delegate: delegate, additionalData: additionalData) + originalAttributedString = attributedText + } + + func styleB2(_ scale: Bool) { + MFStyler.styleLabelB2(self, genericScaling: false) + setScale(scale) + } + + func styleBody(withSize size: CGFloat, scale: Bool) { + MFStyler.styleLabelB2(self, size: size, genericScaling: false) + setScale(scale) + } + + func styleBodyBold(_ scale: Bool) { + MFStyler.styleLabelBodyBold(self, genericScaling: false) + setScale(scale) + } + + func styleBodyLighter(_ scale: Bool) { + MFStyler.styleLabelBodyLighter(self, genericScaling: false) + setScale(scale) + } + + func styleBodyLarge(_ scale: Bool) { + MFStyler.styleLabelBodyLarge(self, genericScaling: false) + setScale(scale) + } + + func styleH1(_ scale: Bool) { + MFStyler.styleLabelH1(self, genericScaling: false) + setScale(scale) + } + + func styleH2(_ scale: Bool) { + MFStyler.styleLabelH2(self, genericScaling: false) + setScale(scale) + } + + func styleHeadlineLarge(_ scale: Bool) { + MFStyler.styleLabelHeadlineLarge(self, genericScaling: false) + setScale(scale) + } + + func styleHeadlineSmall(_ scale: Bool) { + MFStyler.styleLabelHeadlineSmall(self, genericScaling: false) + setScale(scale) + } + + func styleHeadline(withSize size: CGFloat, scale: Bool) { + MFStyler.styleLabelH2(self, size: size, genericScaling: false) + setScale(scale) + } + + func styleHeadlineBlack(withSize size: CGFloat, scale: Bool) { + MFStyler.styleLabelHeadlineBlack(self, size: size, genericScaling: false) + setScale(scale) + } + + func styleH3(_ scale: Bool) { + MFStyler.styleLabelH3(self, genericScaling: false) + setScale(scale) + } + + func styleSubheadBold(_ scale: Bool) { + MFStyler.styleLabelSubheadBold(self, genericScaling: false) + setScale(scale) + } + + func styleSubheadBoldLarge(_ scale: Bool) { + MFStyler.styleLabelSubheadBoldLarge(self, genericScaling: false) + setScale(scale) + } + + func styleB3(_ scale: Bool) { + MFStyler.styleLabelB3(self, genericScaling: false) + setScale(scale) + } + + func styleFeedMessage(_ scale: Bool) { + MFStyler.styleLabelFeedMessage(self, genericScaling: false) + setScale(scale) + } + + func styleFeedSubMessage(_ scale: Bool) { + MFStyler.styleLabelFeedSubMessage(self, genericScaling: false) + setScale(scale) + } + + func styleFeedHeadline(_ scale: Bool) { + MFStyler.styleLabelHeadlineFeed(self, genericScaling: false) + setScale(scale) + } + + func styleFeedTitle(_ scale: Bool) { + MFStyler.styleFeedCardTitleLabel(self, genericScaling: false) + setScale(scale) + } + + func stylePlanCardTitle(_ scale: Bool) { + font = MFStyler.font(forPlanCardTitle: false) + setScale(scale) + } + + func styleB1(_ scale: Bool) { + MFStyler.styleLabelB1(self, genericScaling: false) + setScale(scale) + } + + func styleTableRow(_ scale: Bool) { + MFStyler.styleLabelB1(self, genericScaling: false) + setScale(scale) + } + + func styleTopAlert(_ scale: Bool) { + font = MFStyler.fontB1(false) + setScale(scale) + } + + func setFontH1(_ scale: Bool) { + font = MFStyler.fontH1(false) + setScale(scale) + } +} From 08dc3335683fc86e4f41536d4e692f0d1a08ed02 Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Wed, 3 Apr 2019 11:14:13 -0400 Subject: [PATCH 02/19] Further work on conversion. --- MVMCoreUI/Atoms/Views/Label.swift | 348 +++++++++++++++++------------- 1 file changed, 196 insertions(+), 152 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 1f48273a..fbff2265 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -42,7 +42,16 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } var hasText: Bool { - return text.length > 0 || (attributedText?.length ?? 0) > 0 + + if let text = text, !text.isEmpty { + return true + } + + if let attributedText = attributedText, !attributedText.string.isEmpty { + return true + } + + return false } //------------------------------------------------------ @@ -57,6 +66,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } init() { + super.init(frame: .zero) setupView() } @@ -79,12 +89,12 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { scaleSize = NSNumber(value: Float(size)) - if originalAttributedString { + if let originalAttributedString = originalAttributedString { var attributedString = NSMutableAttributedString(attributedString: originalAttributedString) attributedString.removeAttribute(.font, range: NSRange(location: 0, length: attributedString.length)) originalAttributedString.enumerateAttribute(.font, in: NSRange(location: 0, length: originalAttributedString.length), options: [], using: { value, range, stop in // Loop the original attributed string, resize the fonts. - let font: UIFont? = value?.withSize(MFStyler.sizeObjectGeneric(forCurrentDevice: value?.pointSize).getValueBased(onSize: size)) + let font: UIFont? = (value? as AnyObject).withSize(MFStyler.sizeObjectGeneric(forCurrentDevice: value?.pointSize).getValueBased(onSize: size)) attributedString.addAttribute(.font, value: font, range: range) }) attributedText = attributedString @@ -115,155 +125,100 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { return Label(frame: CGRect.zero) } - class func commonLabelB2(_ scale: Bool) -> Label { - let label = Label.label() - label.styleB2(scale) - return label - } - - class func commonLabelBody(withSize size: CGFloat, scale: Bool) -> Label { - let label = Label.label() - label.styleBody(withSize: size, scale: scale) - return label - } - - class func commonLabelBodyBold(_ scale: Bool) -> Label { - let label = Label() - label.styleBodyBold(scale) - return label - } - - class func commonLabelBodyLighter(_ scale: Bool) -> Label { - let label = Label() - label.styleBodyLighter(scale) - return label - } - - class func commonLabelBodyLarge(_ scale: Bool) -> Label { - let label = Label() - label.styleBodyLarge(scale) - return label - } - - class func commonLabelH1(_ scale: Bool) -> Label { - let label = Label() - label.styleH1(scale) - return label - } - - class func commonLabelH2(_ scale: Bool) -> Label { - let label = Label() - label.styleH2(scale) - return label - } - - class func commonLabelHeadlineSmall(_ scale: Bool) -> Label { - let label = Label() - label.styleHeadlineSmall(scale) - return label - } - - class func commonLabelHeadline(withSize size: CGFloat, scale: Bool) -> Label { - let label = Label() - label.styleHeadline(withSize: size, scale: scale) - return label - } - - class func commonLabelHeadlineBlack(withSize size: CGFloat, scale: Bool) -> Label { - let label = Label() - label.styleHeadlineBlack(withSize: size, scale: scale) - return label - } - - class func commonLabelH3(_ scale: Bool) -> Label { - let label = Label() - label.styleH3(scale) - return label - } - - class func commonLabelSubheadBold(_ scale: Bool) -> Label { - let label = Label() - label.styleSubheadBold(scale) - return label - } - - class func commonLabelSubheadBoldLarge(_ scale: Bool) -> Label { - let label = Label() - label.styleSubheadBoldLarge(scale) - return label - } - - class func commonLabelB3(_ scale: Bool) -> Label { - let label = Label() - label.styleB3(scale) - return label - } - - class func commonLabelFeedMessage(_ scale: Bool) -> Label { - let label = Label() - label.styleFeedMessage(scale) - return label - } - - class func commonLabelFeedSubMessage(_ scale: Bool) -> Label { - let label = Label() - label.styleFeedSubMessage(scale) - return label - } - - class func commonLabelFeedHeadline(_ scale: Bool) -> Label { - let label = Label() - label.styleFeedHeadline(scale) - return label - } - - class func commonLabelFeedTitle(_ scale: Bool) -> Label { - let label = Label() - label.styleFeedTitle(scale) - return label - } - - class func commonLabelPlanCardTitle(_ scale: Bool) -> Label { - let label = Label() - label.stylePlanCardTitle(scale) - return label - } - - class func commonLabelB1(_ scale: Bool) -> Label { - let label = Label() - label.styleB1(scale) - return label - } - - class func commonLabelTopAlert(_ scale: Bool) -> Label { - let label = Label() - label.styleTopAlert(scale) - return label - } - - class func setLabel(_ label: UILabel?, withHTML html: String?) { - let data: Data? = html?.data(using: .utf8) - if data != nil { - var error: Error? = nil - if let data = data { - label?.attributedText = try? NSAttributedString(data: data, - options: [NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.html.rawValue as Any], - documentAttributes: nil) - } - if let labelError = error { - try? MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: labelError, location: "LabelHTMLParse")) - } - } - } - - class func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { + enum Style { + case commonLabelB2(scale: Bool) + case commonLabelBody(size: CGFloat, scale: Bool) + case commonLabelBodyBold(scale: Bool) + case commonLabelBodyLighter(scale: Bool) + case commonLabelBodyLarge(scale: Bool) + case commonLabelH1(scale: Bool) + case commonLabelH2(scale: Bool) + case commonLabelHeadlineSmall(scale: Bool) + case commonLabelHeadline(size: CGFloat, scale: Bool) + case commonLabelHeadlineBlack(size: CGFloat, scale: Bool) + case commonLabelH3(scale: Bool) + case commonLabelSubheadBold(scale: Bool) + case commonLabelSubheadBoldLarge(scale: Bool) + case commonLabelB3(scale: Bool) + case commonLabelFeedMessage(scale: Bool) + case commonLabelFeedSubMessage(scale: Bool) + case commonLabelFeedHeadline(scale: Bool) + case commonLabelFeedTitle(scale: Bool) + case commonLabelPlanCardTitle(scale: Bool) + case commonLabelB1(scale: Bool) + case commonLabelTopAlert(scale: Bool) - // TODO: !!! - } - - func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { - Label.setUILabel(self, withJSON: json, delegate: delegate, additionalData: additionalData) - originalAttributedString = attributedText + func getLabel() -> Label { + + let label = Label() + + switch self { + case .commonLabelB2(let scale): + label.styleB2(scale) + + case .commonLabelBody(let size, let scale): + label.styleBody(withSize: size, scale: scale) + + case .commonLabelBodyBold(let scale): + label.styleBodyBold(scale) + + case .commonLabelBodyLighter(let scale): + label.styleBodyLighter(scale) + + case .commonLabelBodyLarge(let scale): + label.styleBodyLarge(scale) + + case .commonLabelH1(let scale): + label.styleH1(scale) + + case .commonLabelH2(let scale): + label.styleH2(scale) + + case .commonLabelHeadlineSmall(let scale): + label.styleHeadlineSmall(scale) + + case .commonLabelHeadline(let size, let scale): + label.styleHeadline(withSize: size, scale: scale) + + case .commonLabelHeadlineBlack(let size, let scale): + label.styleHeadlineBlack(withSize: size, scale: scale) + + case .commonLabelH3(let scale): + label.styleH3(scale) + + case .commonLabelSubheadBold(let scale): + label.styleSubheadBold(scale) + + case .commonLabelSubheadBoldLarge(let scale): + label.styleSubheadBoldLarge(scale) + + case .commonLabelB3(let scale): + label.styleB3(scale) + + case .commonLabelFeedMessage(let scale): + label.styleFeedMessage(scale) + + case .commonLabelFeedSubMessage(let scale): + label.styleFeedSubMessage(scale) + + case .commonLabelFeedHeadline(let scale): + label.styleFeedHeadline(scale) + + case .commonLabelFeedTitle(let scale): + label.styleFeedTitle(scale) + + case .commonLabelPlanCardTitle(let scale): + label.stylePlanCardTitle(scale) + + case .commonLabelB1(let scale): + label.styleB1(scale) + + case .commonLabelTopAlert(let scale): + label.styleTopAlert(scale) + } + + return label + } } func styleB2(_ scale: Bool) { @@ -345,7 +300,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { MFStyler.styleLabelFeedMessage(self, genericScaling: false) setScale(scale) } - + func styleFeedSubMessage(_ scale: Bool) { MFStyler.styleLabelFeedSubMessage(self, genericScaling: false) setScale(scale) @@ -385,4 +340,93 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { font = MFStyler.fontH1(false) setScale(scale) } + + class func setLabel(_ label: UILabel?, withHTML html: String?) { + let data: Data? = html?.data(using: .utf8) + if data != nil { + var error: Error? = nil + if let data = data { + label?.attributedText = try? NSAttributedString(data: data, + options: [NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.html.rawValue], + documentAttributes: nil) + } + if let labelError = error { + try? MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: labelError, location: "LabelHTMLParse")) + } + } + } + + class func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { + + if let label = label { + label.text = json?.optionalStringForKey(KeyText) + setLabel(label, withHTML: json?.stringForkey("html")) + + if let textColorHex = json?.optionalStringForKey(KeyTextColor) { + label.textColor = UIColor.mfGet(forHex: textColorHex) + } + + if let backgroundColorHex = json?.optionalStringForKey(KeyBackgroundColor) { + label.backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) + } + + if let accessibilityText = json?.optionalStringForKey("accessibilityText") { + label.accessibilityLabel = accessibilityText + } + + var fontSize = json?.floatForKey("fontSize") + + if let fontName = json?.optionalStringForKey("fontName"), let fontSize = fontSize { + label.font = MFFonts.mfFont(withName: fontName, size: CGFloat(fontSize) == 0.0 ? label.font.pointSize : CGFloat(fontSize)) + } else if let fontSize = fontSize { + label.font = label.font.withSize(CGFloat(fontSize)) + } + + if let attributes = json?.arrayForKey("attributes") { + var attributedString = NSMutableAttributedString(string: label.text, attributes: [NSAttributedString.Key.font: label.font, + NSAttributedString.Key.foregroundColor: label.textColor]) + for case let attribute as [String: Any] in attributes { + var location = attribute.optionalNumber(forKey: "location") + var length = attribute.optionalNumber(forKey: "length") + if location && length { + + var range = NSRange(location: Int(location.uintValue), length: Int(length.uintValue)) + var type = attribute.string(KeyType) + + if type == "underline" { + attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range) + + } else if type == "strikethrough" { + attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick, range: range) + + } else if type == "color" { + if let colorHex = attribute.optionalStringForKey(KeyTextColor), !colorHex.isEmpty { + attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range) + } + } else if type == "font" { + + var fontSize = attribute.floatForKey("size") + var font: UIFont? + + if let fontName = attribute.optionalStringForKey("name"), !fontName.isEmpty { + font = MFFonts.mfFont(withName: fontName, size: fontSize != 0.0 ? CGFloat(fontSize) : CGFloat(label.font.pointSize)) + } else { + font = label.font.withSize(CGFloat(fontSize)) + } + + if font != nil { + attributedString.addAttribute(.font, value: font, range: range) + } + } + } + } + label.attributedText = attributedString + } + } + } + + func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { + Label.setUILabel(self, withJSON: json, delegate: delegate, additionalData: additionalData) + originalAttributedString = attributedText + } } From ce68eafd348182bbb82ab231c9bb365e73b48f50 Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Wed, 3 Apr 2019 13:31:29 -0400 Subject: [PATCH 03/19] stopping for now. --- MVMCoreUI/Atoms/Views/Label.swift | 106 ++++++++++++++++++------------ 1 file changed, 65 insertions(+), 41 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index fbff2265..88b07f00 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -59,6 +59,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { //------------------------------------------------------ func setupView() { + backgroundColor = UIColor.clear numberOfLines = 0 lineBreakMode = NSLineBreakMode.byWordWrapping @@ -85,24 +86,32 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { standardFontSize = size } + //------------------------------------------------------ + // MARK: - Functions + //------------------------------------------------------ + func updateView(_ size: CGFloat) { scaleSize = NSNumber(value: Float(size)) if let originalAttributedString = originalAttributedString { - var attributedString = NSMutableAttributedString(attributedString: originalAttributedString) + let attributedString = NSMutableAttributedString(attributedString: originalAttributedString) attributedString.removeAttribute(.font, range: NSRange(location: 0, length: attributedString.length)) + originalAttributedString.enumerateAttribute(.font, in: NSRange(location: 0, length: originalAttributedString.length), options: [], using: { value, range, stop in // Loop the original attributed string, resize the fonts. - let font: UIFont? = (value? as AnyObject).withSize(MFStyler.sizeObjectGeneric(forCurrentDevice: value?.pointSize).getValueBased(onSize: size)) - attributedString.addAttribute(.font, value: font, range: range) + let font: UIFont? = (value as? UIFont)?.withSize((MFStyler.sizeObjectGeneric(forCurrentDevice: ((value as? UIFont)?.pointSize)!)?.getValueBased(onSize: size))!) + attributedString.addAttribute(.font, value: font as Any, range: range) }) attributedText = attributedString - } else if !fequal(standardFontSize, 0) { + + } else if !MVMCoreGetterUtility.fequal(a: Float(standardFontSize), b: 0.0) { var sizeObject: MFSizeObject? = self.sizeObject + if sizeObject == nil { sizeObject = MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) } + self.font = self.font.withSize(sizeObject?.getValueBased(onSize: size) ?? 0.0) } } @@ -115,7 +124,11 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { func setScale(_ scale: Bool) { if scale { standardFontSize = font.pointSize - updateView((scaleSize ? CGFloat(scaleSize?.floatValue ?? 0) : MVMCoreUISplitViewController.getApplicationViewWidth())) + if let scaleSize = scaleSize { + updateView(CGFloat(scaleSize.floatValue)) + } else { + updateView(MVMCoreUISplitViewController.getApplicationViewWidth()) + } } else { standardFontSize = 0 } @@ -148,7 +161,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { case commonLabelB1(scale: Bool) case commonLabelTopAlert(scale: Bool) - func getLabel() -> Label { + func createLabel() -> Label { let label = Label() @@ -221,6 +234,10 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } } + //------------------------------------------------------ + // MARK: - Methods + //------------------------------------------------------ + func styleB2(_ scale: Bool) { MFStyler.styleLabelB2(self, genericScaling: false) setScale(scale) @@ -344,14 +361,14 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { class func setLabel(_ label: UILabel?, withHTML html: String?) { let data: Data? = html?.data(using: .utf8) if data != nil { - var error: Error? = nil + let error: Error? = nil if let data = data { label?.attributedText = try? NSAttributedString(data: data, - options: [NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.html.rawValue], + options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil) } if let labelError = error { - try? MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: labelError, location: "LabelHTMLParse")) + try? MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: labelError, location: "LabelHTMLParse")!) } } } @@ -374,7 +391,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { label.accessibilityLabel = accessibilityText } - var fontSize = json?.floatForKey("fontSize") + let fontSize = json?.floatForKey("fontSize") if let fontName = json?.optionalStringForKey("fontName"), let fontSize = fontSize { label.font = MFFonts.mfFont(withName: fontName, size: CGFloat(fontSize) == 0.0 ? label.font.pointSize : CGFloat(fontSize)) @@ -382,42 +399,41 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { label.font = label.font.withSize(CGFloat(fontSize)) } - if let attributes = json?.arrayForKey("attributes") { - var attributedString = NSMutableAttributedString(string: label.text, attributes: [NSAttributedString.Key.font: label.font, + if let attributes = json?.arrayForKey("attributes"), let labelText = label.text { + let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font, NSAttributedString.Key.foregroundColor: label.textColor]) for case let attribute as [String: Any] in attributes { - var location = attribute.optionalNumber(forKey: "location") - var length = attribute.optionalNumber(forKey: "length") - if location && length { + let location = attribute.floatForKey("location") + let length = attribute.floatForKey("length") + + let range = NSRange(location: Int(location), length: Int(length)) + + switch attribute.stringForkey(KeyType){ + case "underline": + attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range) - var range = NSRange(location: Int(location.uintValue), length: Int(length.uintValue)) - var type = attribute.string(KeyType) + case "strikethrough": + attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick, range: range) - if type == "underline" { - attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range) - - } else if type == "strikethrough" { - attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick, range: range) - - } else if type == "color" { - if let colorHex = attribute.optionalStringForKey(KeyTextColor), !colorHex.isEmpty { - attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range) - } - } else if type == "font" { - - var fontSize = attribute.floatForKey("size") - var font: UIFont? - - if let fontName = attribute.optionalStringForKey("name"), !fontName.isEmpty { - font = MFFonts.mfFont(withName: fontName, size: fontSize != 0.0 ? CGFloat(fontSize) : CGFloat(label.font.pointSize)) - } else { - font = label.font.withSize(CGFloat(fontSize)) - } - - if font != nil { - attributedString.addAttribute(.font, value: font, range: range) - } + case "color": + if let colorHex = attribute.optionalStringForKey(KeyTextColor), !colorHex.isEmpty { + attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range) } + case "font": + let fontSize = attribute.floatForKey("size") + var font: UIFont? + + if let fontName = attribute.optionalStringForKey("name"), !fontName.isEmpty { + font = MFFonts.mfFont(withName: fontName, size: fontSize != 0.0 ? CGFloat(fontSize) : CGFloat(label.font.pointSize)) + } else { + font = label.font.withSize(CGFloat(fontSize)) + } + + if font != nil { + attributedString.addAttribute(.font, value: font as Any, range: range) + } + default: + continue } } label.attributedText = attributedString @@ -425,6 +441,14 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } } + //------------------------------------------------------ + // MARK: - Atomization + //------------------------------------------------------ + + func setAsMolecule() { + // Empty + } + func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { Label.setUILabel(self, withJSON: json, delegate: delegate, additionalData: additionalData) originalAttributedString = attributedText From edde99cc23cbeee7cab9539849bbfa1713dd32ad Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Sun, 7 Apr 2019 20:18:40 -0400 Subject: [PATCH 04/19] Changes made to satisfy update to MFLabel. --- MVMCoreUI.xcodeproj/project.pbxproj | 4 +- MVMCoreUI/Atoms/Views/Label.swift | 491 +++++++++++----------------- 2 files changed, 186 insertions(+), 309 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 5d4a752c..5731bd78 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -157,10 +157,10 @@ D2C5001921F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */; }; D2C5001D21F8EE67001DA659 /* LabelWithInternalButton.h in Headers */ = {isa = PBXBuildFile; fileRef = D2C5001B21F8EE66001DA659 /* LabelWithInternalButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; D2C5001E21F8EE67001DA659 /* LabelWithInternalButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D2C5001C21F8EE66001DA659 /* LabelWithInternalButton.m */; }; - DB891E832253FA8500022516 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB891E822253FA8500022516 /* Label.swift */; }; DBC4391822442197001AB423 /* CaretView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391622442196001AB423 /* CaretView.swift */; }; DBC4391922442197001AB423 /* DashLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391722442197001AB423 /* DashLine.swift */; }; DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391A224421A0001AB423 /* CaretButton.swift */; }; + DBEFFA04225A829700230692 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB891E822253FA8500022516 /* Label.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -886,6 +886,7 @@ D29DF25421E6A177003B2FB9 /* MFMdnTextField.m in Sources */, D282AABA224131D100C46919 /* MFTransparentGIFView.swift in Sources */, D2A514672213885800345BFB /* StandardHeaderView.swift in Sources */, + DBEFFA04225A829700230692 /* Label.swift in Sources */, D29DF13021E6851E003B2FB9 /* MVMCoreUITopAlertShortView.m in Sources */, D28B4F8B21FF967C00712C7A /* MVMCoreUIObject.m in Sources */, D29DF26D21E6AA0B003B2FB9 /* FLAnimatedImageView.m in Sources */, @@ -893,7 +894,6 @@ D282AACB2243C61700C46919 /* ButtonView.swift in Sources */, 0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */, D29DF2AE21E7B3A4003B2FB9 /* MFTextView.m in Sources */, - DB891E832253FA8500022516 /* Label.swift in Sources */, D29DF18121E69E50003B2FB9 /* MFView.m in Sources */, D29DF18321E69E54003B2FB9 /* SeparatorView.m in Sources */, D29DF17A21E69E1F003B2FB9 /* MFCustomButton.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 88b07f00..61bf9a12 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -54,6 +54,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { return false } + //------------------------------------------------------ // MARK: - Initialization //------------------------------------------------------ @@ -86,10 +87,193 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { standardFontSize = size } + //------------------------------------------------------ + // MARK: - Enum + //------------------------------------------------------ + + enum Style { + case commonLabelB2(scale: Bool) + case commonLabelH1(scale: Bool) + case commonLabelH2(scale: Bool) + case commonLabelH32(scale: Bool) + case commonLabelH3(scale: Bool) + case commonLabelB3(scale: Bool) + case commonLabelB20(scale: Bool) + case commonLabelB1(scale: Bool) + + func createLabel() -> Label { + + let label = Label() + + switch self { + case .commonLabelB2(let scale): + label.styleB2(scale) + + case .commonLabelH1(let scale): + label.styleH1(scale) + + case .commonLabelH2(let scale): + label.styleH2(scale) + + case .commonLabelH32(let scale): + label.styleH32(scale) + + case .commonLabelH3(let scale): + label.styleH3(scale) + + case .commonLabelB3(let scale): + label.styleB3(scale) + + case .commonLabelB20(let scale): + label.styleB20(scale) + + case .commonLabelB1(let scale): + label.styleB1(scale) + } + + return label + } + } + //------------------------------------------------------ // MARK: - Functions //------------------------------------------------------ + static func label() -> Label { + return Label(frame: CGRect.zero) + } + + static func setLabel(_ label: UILabel?, withHTML html: String?) { + let data: Data? = html?.data(using: .utf8) + if data != nil { + let error: Error? = nil + if let data = data { + label?.attributedText = try? NSAttributedString(data: data, + options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue], + documentAttributes: nil) + + // label?.attributedText = try? NSAttributedString(data: data, options: [ + // NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.html.rawValue + // ], documentAttributes: nil) + } + if let labelError = error { + try? MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: labelError, location: "LabelHTMLParse")!) + } + } + } + + static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { + + if let label = label { + label.text = json?.optionalStringForKey(KeyText) + setLabel(label, withHTML: json?.stringForkey("html")) + + if let textColorHex = json?.optionalStringForKey(KeyTextColor) { + label.textColor = UIColor.mfGet(forHex: textColorHex) + } + + if let backgroundColorHex = json?.optionalStringForKey(KeyBackgroundColor) { + label.backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) + } + + if let accessibilityText = json?.optionalStringForKey("accessibilityText") { + label.accessibilityLabel = accessibilityText + } + + let fontSize = json?.floatForKey("fontSize") + + if let fontName = json?.optionalStringForKey("fontName"), let fontSize = fontSize { + label.font = MFFonts.mfFont(withName: fontName, size: CGFloat(fontSize) == 0.0 ? label.font.pointSize : CGFloat(fontSize)) + } else if let fontSize = fontSize { + label.font = label.font.withSize(CGFloat(fontSize)) + } + + if let attributes = json?.arrayForKey("attributes"), let labelText = label.text { + let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font, + NSAttributedString.Key.foregroundColor: label.textColor]) + for case let attribute as [String: Any] in attributes { + let location = attribute.floatForKey("location") + let length = attribute.floatForKey("length") + + let range = NSRange(location: Int(location), length: Int(length)) + + switch attribute.stringForkey(KeyType){ + case "underline": + attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range) + + case "strikethrough": + attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick, range: range) + + case "color": + if let colorHex = attribute.optionalStringForKey(KeyTextColor), !colorHex.isEmpty { + attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range) + } + case "font": + let fontSize = attribute.floatForKey("size") + var font: UIFont? + + if let fontName = attribute.optionalStringForKey("name"), !fontName.isEmpty { + font = MFFonts.mfFont(withName: fontName, size: fontSize != 0.0 ? CGFloat(fontSize) : CGFloat(label.font.pointSize)) + } else { + font = label.font.withSize(CGFloat(fontSize)) + } + + if font != nil { + attributedString.addAttribute(.font, value: font as Any, range: range) + } + default: + continue + } + } + label.attributedText = attributedString + } + } + } + + //------------------------------------------------------ + // MARK: - Methods + //------------------------------------------------------ + + func styleH1(_ scale: Bool) { + MFStyler.styleLabelH1(self, genericScaling: false) + setScale(scale) + } + + func styleH2(_ scale: Bool) { + MFStyler.styleLabelH2(self, genericScaling: false) + setScale(scale) + } + + func styleH3(_ scale: Bool) { + MFStyler.styleLabelH3(self, genericScaling: false) + setScale(scale) + } + + func styleH32(_ scale: Bool) { + MFStyler.styleLabelH32(self, genericScaling: false) + setScale(scale) + } + + func styleB1(_ scale: Bool) { + MFStyler.styleLabelB1(self, genericScaling: false) + setScale(scale) + } + + func styleB2(_ scale: Bool) { + MFStyler.styleLabelB2(self, genericScaling: false) + setScale(scale) + } + + func styleB3(_ scale: Bool) { + MFStyler.styleLabelB3(self, genericScaling: false) + setScale(scale) + } + + func styleB20(_ scale: Bool) { + MFStyler.styleLabelB20(self, genericScaling: false) + setScale(scale) + } + func updateView(_ size: CGFloat) { scaleSize = NSNumber(value: Float(size)) @@ -134,313 +318,6 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } } - class func label() -> Label { - return Label(frame: CGRect.zero) - } - - enum Style { - case commonLabelB2(scale: Bool) - case commonLabelBody(size: CGFloat, scale: Bool) - case commonLabelBodyBold(scale: Bool) - case commonLabelBodyLighter(scale: Bool) - case commonLabelBodyLarge(scale: Bool) - case commonLabelH1(scale: Bool) - case commonLabelH2(scale: Bool) - case commonLabelHeadlineSmall(scale: Bool) - case commonLabelHeadline(size: CGFloat, scale: Bool) - case commonLabelHeadlineBlack(size: CGFloat, scale: Bool) - case commonLabelH3(scale: Bool) - case commonLabelSubheadBold(scale: Bool) - case commonLabelSubheadBoldLarge(scale: Bool) - case commonLabelB3(scale: Bool) - case commonLabelFeedMessage(scale: Bool) - case commonLabelFeedSubMessage(scale: Bool) - case commonLabelFeedHeadline(scale: Bool) - case commonLabelFeedTitle(scale: Bool) - case commonLabelPlanCardTitle(scale: Bool) - case commonLabelB1(scale: Bool) - case commonLabelTopAlert(scale: Bool) - - func createLabel() -> Label { - - let label = Label() - - switch self { - case .commonLabelB2(let scale): - label.styleB2(scale) - - case .commonLabelBody(let size, let scale): - label.styleBody(withSize: size, scale: scale) - - case .commonLabelBodyBold(let scale): - label.styleBodyBold(scale) - - case .commonLabelBodyLighter(let scale): - label.styleBodyLighter(scale) - - case .commonLabelBodyLarge(let scale): - label.styleBodyLarge(scale) - - case .commonLabelH1(let scale): - label.styleH1(scale) - - case .commonLabelH2(let scale): - label.styleH2(scale) - - case .commonLabelHeadlineSmall(let scale): - label.styleHeadlineSmall(scale) - - case .commonLabelHeadline(let size, let scale): - label.styleHeadline(withSize: size, scale: scale) - - case .commonLabelHeadlineBlack(let size, let scale): - label.styleHeadlineBlack(withSize: size, scale: scale) - - case .commonLabelH3(let scale): - label.styleH3(scale) - - case .commonLabelSubheadBold(let scale): - label.styleSubheadBold(scale) - - case .commonLabelSubheadBoldLarge(let scale): - label.styleSubheadBoldLarge(scale) - - case .commonLabelB3(let scale): - label.styleB3(scale) - - case .commonLabelFeedMessage(let scale): - label.styleFeedMessage(scale) - - case .commonLabelFeedSubMessage(let scale): - label.styleFeedSubMessage(scale) - - case .commonLabelFeedHeadline(let scale): - label.styleFeedHeadline(scale) - - case .commonLabelFeedTitle(let scale): - label.styleFeedTitle(scale) - - case .commonLabelPlanCardTitle(let scale): - label.stylePlanCardTitle(scale) - - case .commonLabelB1(let scale): - label.styleB1(scale) - - case .commonLabelTopAlert(let scale): - label.styleTopAlert(scale) - } - - return label - } - } - - //------------------------------------------------------ - // MARK: - Methods - //------------------------------------------------------ - - func styleB2(_ scale: Bool) { - MFStyler.styleLabelB2(self, genericScaling: false) - setScale(scale) - } - - func styleBody(withSize size: CGFloat, scale: Bool) { - MFStyler.styleLabelB2(self, size: size, genericScaling: false) - setScale(scale) - } - - func styleBodyBold(_ scale: Bool) { - MFStyler.styleLabelBodyBold(self, genericScaling: false) - setScale(scale) - } - - func styleBodyLighter(_ scale: Bool) { - MFStyler.styleLabelBodyLighter(self, genericScaling: false) - setScale(scale) - } - - func styleBodyLarge(_ scale: Bool) { - MFStyler.styleLabelBodyLarge(self, genericScaling: false) - setScale(scale) - } - - func styleH1(_ scale: Bool) { - MFStyler.styleLabelH1(self, genericScaling: false) - setScale(scale) - } - - func styleH2(_ scale: Bool) { - MFStyler.styleLabelH2(self, genericScaling: false) - setScale(scale) - } - - func styleHeadlineLarge(_ scale: Bool) { - MFStyler.styleLabelHeadlineLarge(self, genericScaling: false) - setScale(scale) - } - - func styleHeadlineSmall(_ scale: Bool) { - MFStyler.styleLabelHeadlineSmall(self, genericScaling: false) - setScale(scale) - } - - func styleHeadline(withSize size: CGFloat, scale: Bool) { - MFStyler.styleLabelH2(self, size: size, genericScaling: false) - setScale(scale) - } - - func styleHeadlineBlack(withSize size: CGFloat, scale: Bool) { - MFStyler.styleLabelHeadlineBlack(self, size: size, genericScaling: false) - setScale(scale) - } - - func styleH3(_ scale: Bool) { - MFStyler.styleLabelH3(self, genericScaling: false) - setScale(scale) - } - - func styleSubheadBold(_ scale: Bool) { - MFStyler.styleLabelSubheadBold(self, genericScaling: false) - setScale(scale) - } - - func styleSubheadBoldLarge(_ scale: Bool) { - MFStyler.styleLabelSubheadBoldLarge(self, genericScaling: false) - setScale(scale) - } - - func styleB3(_ scale: Bool) { - MFStyler.styleLabelB3(self, genericScaling: false) - setScale(scale) - } - - func styleFeedMessage(_ scale: Bool) { - MFStyler.styleLabelFeedMessage(self, genericScaling: false) - setScale(scale) - } - - func styleFeedSubMessage(_ scale: Bool) { - MFStyler.styleLabelFeedSubMessage(self, genericScaling: false) - setScale(scale) - } - - func styleFeedHeadline(_ scale: Bool) { - MFStyler.styleLabelHeadlineFeed(self, genericScaling: false) - setScale(scale) - } - - func styleFeedTitle(_ scale: Bool) { - MFStyler.styleFeedCardTitleLabel(self, genericScaling: false) - setScale(scale) - } - - func stylePlanCardTitle(_ scale: Bool) { - font = MFStyler.font(forPlanCardTitle: false) - setScale(scale) - } - - func styleB1(_ scale: Bool) { - MFStyler.styleLabelB1(self, genericScaling: false) - setScale(scale) - } - - func styleTableRow(_ scale: Bool) { - MFStyler.styleLabelB1(self, genericScaling: false) - setScale(scale) - } - - func styleTopAlert(_ scale: Bool) { - font = MFStyler.fontB1(false) - setScale(scale) - } - - func setFontH1(_ scale: Bool) { - font = MFStyler.fontH1(false) - setScale(scale) - } - - class func setLabel(_ label: UILabel?, withHTML html: String?) { - let data: Data? = html?.data(using: .utf8) - if data != nil { - let error: Error? = nil - if let data = data { - label?.attributedText = try? NSAttributedString(data: data, - options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue], - documentAttributes: nil) - } - if let labelError = error { - try? MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: labelError, location: "LabelHTMLParse")!) - } - } - } - - class func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { - - if let label = label { - label.text = json?.optionalStringForKey(KeyText) - setLabel(label, withHTML: json?.stringForkey("html")) - - if let textColorHex = json?.optionalStringForKey(KeyTextColor) { - label.textColor = UIColor.mfGet(forHex: textColorHex) - } - - if let backgroundColorHex = json?.optionalStringForKey(KeyBackgroundColor) { - label.backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) - } - - if let accessibilityText = json?.optionalStringForKey("accessibilityText") { - label.accessibilityLabel = accessibilityText - } - - let fontSize = json?.floatForKey("fontSize") - - if let fontName = json?.optionalStringForKey("fontName"), let fontSize = fontSize { - label.font = MFFonts.mfFont(withName: fontName, size: CGFloat(fontSize) == 0.0 ? label.font.pointSize : CGFloat(fontSize)) - } else if let fontSize = fontSize { - label.font = label.font.withSize(CGFloat(fontSize)) - } - - if let attributes = json?.arrayForKey("attributes"), let labelText = label.text { - let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font, - NSAttributedString.Key.foregroundColor: label.textColor]) - for case let attribute as [String: Any] in attributes { - let location = attribute.floatForKey("location") - let length = attribute.floatForKey("length") - - let range = NSRange(location: Int(location), length: Int(length)) - - switch attribute.stringForkey(KeyType){ - case "underline": - attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range) - - case "strikethrough": - attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick, range: range) - - case "color": - if let colorHex = attribute.optionalStringForKey(KeyTextColor), !colorHex.isEmpty { - attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range) - } - case "font": - let fontSize = attribute.floatForKey("size") - var font: UIFont? - - if let fontName = attribute.optionalStringForKey("name"), !fontName.isEmpty { - font = MFFonts.mfFont(withName: fontName, size: fontSize != 0.0 ? CGFloat(fontSize) : CGFloat(label.font.pointSize)) - } else { - font = label.font.withSize(CGFloat(fontSize)) - } - - if font != nil { - attributedString.addAttribute(.font, value: font as Any, range: range) - } - default: - continue - } - } - label.attributedText = attributedString - } - } - } - //------------------------------------------------------ // MARK: - Atomization //------------------------------------------------------ From 39ce8af7ab2ba4fa537deca2308b30e5e56788d9 Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Tue, 9 Apr 2019 15:18:14 -0400 Subject: [PATCH 05/19] further work on conversion. --- MVMCoreUI/Atoms/Views/Label.swift | 118 ++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 32 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 61bf9a12..2b491d07 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -54,7 +54,6 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { return false } - //------------------------------------------------------ // MARK: - Initialization //------------------------------------------------------ @@ -88,61 +87,115 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } //------------------------------------------------------ - // MARK: - Enum + // MARK: - Enum Generator //------------------------------------------------------ enum Style { - case commonLabelB2(scale: Bool) - case commonLabelH1(scale: Bool) - case commonLabelH2(scale: Bool) - case commonLabelH32(scale: Bool) - case commonLabelH3(scale: Bool) - case commonLabelB3(scale: Bool) - case commonLabelB20(scale: Bool) - case commonLabelB1(scale: Bool) + case B1(scale: Bool) + case B2(scale: Bool) + case B3(scale: Bool) + case B20(scale: Bool) + case H1(scale: Bool) + case H2(scale: Bool) + case H3(scale: Bool) + case H32(scale: Bool) + case none - func createLabel() -> Label { + func create() -> Label { let label = Label() switch self { - case .commonLabelB2(let scale): + case .B1(let scale): + label.styleB1(scale) + + case .B2(let scale): label.styleB2(scale) - case .commonLabelH1(let scale): - label.styleH1(scale) - - case .commonLabelH2(let scale): - label.styleH2(scale) - - case .commonLabelH32(let scale): - label.styleH32(scale) - - case .commonLabelH3(let scale): - label.styleH3(scale) - - case .commonLabelB3(let scale): + case .B3(let scale): label.styleB3(scale) - case .commonLabelB20(let scale): + case .B20(let scale): label.styleB20(scale) - case .commonLabelB1(let scale): - label.styleB1(scale) + case .H1(let scale): + label.styleH1(scale) + + case .H2(let scale): + label.styleH2(scale) + + case .H3(let scale): + label.styleH3(scale) + + case .H32(let scale): + label.styleH32(scale) + + case .none: + break; } return label } } + + /* + class func commonLabelH1(_ scale: Bool) -> MFLabel { + let label = MFLabel.label() + label.styleH1(scale) + return label + } + + class func commonLabelH2(_ scale: Bool) -> MFLabel { + let label = MFLabel.label() + label.styleH2(scale) + return label + } + + class func commonLabelH3(_ scale: Bool) -> MFLabel { + let label = MFLabel.label() + label.styleH3(scale) + return label + } + + class func commonLabelH32(_ scale: Bool) -> MFLabel { + let label = MFLabel.label() + label.styleH32(scale) + return label + } + + class func commonLabelB1(_ scale: Bool) -> MFLabel { + let label = MFLabel.label() + label.styleB1(scale) + return label + } + + class func commonLabelB2(_ scale: Bool) -> MFLabel { + let label = MFLabel.label() + label.styleB2(scale) + return label + } + + class func commonLabelB3(_ scale: Bool) -> MFLabel { + let label = MFLabel.label() + label.styleB3(scale) + return label + } + + class func commonLabelB20(_ scale: Bool) -> MFLabel { + let label = MFLabel.label() + label.styleB20(scale) + return label + } + + class func label() -> MFLabel { + return Label(frame: CGRect.zero) + } + */ //------------------------------------------------------ // MARK: - Functions //------------------------------------------------------ - static func label() -> Label { - return Label(frame: CGRect.zero) - } - static func setLabel(_ label: UILabel?, withHTML html: String?) { let data: Data? = html?.data(using: .utf8) if data != nil { @@ -152,6 +205,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil) + // compare with above... // label?.attributedText = try? NSAttributedString(data: data, options: [ // NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.html.rawValue // ], documentAttributes: nil) From 0e5582beedc428ff16f2fd3ab29f5077a7e88995 Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Wed, 10 Apr 2019 16:33:47 -0400 Subject: [PATCH 06/19] Removing enum. won't bridge to objc correctly. --- MVMCoreUI/Atoms/Views/Label.swift | 89 +++++++------------------------ 1 file changed, 20 insertions(+), 69 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 2b491d07..b0b32fcc 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -87,110 +87,61 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } //------------------------------------------------------ - // MARK: - Enum Generator + // MARK: - Functions //------------------------------------------------------ - - enum Style { - case B1(scale: Bool) - case B2(scale: Bool) - case B3(scale: Bool) - case B20(scale: Bool) - case H1(scale: Bool) - case H2(scale: Bool) - case H3(scale: Bool) - case H32(scale: Bool) - case none - - func create() -> Label { - - let label = Label() - - switch self { - case .B1(let scale): - label.styleB1(scale) - - case .B2(let scale): - label.styleB2(scale) - - case .B3(let scale): - label.styleB3(scale) - - case .B20(let scale): - label.styleB20(scale) - - case .H1(let scale): - label.styleH1(scale) - - case .H2(let scale): - label.styleH2(scale) - - case .H3(let scale): - label.styleH3(scale) - - case .H32(let scale): - label.styleH32(scale) - - case .none: - break; - } - - return label - } - } - - /* - class func commonLabelH1(_ scale: Bool) -> MFLabel { - let label = MFLabel.label() + + class func commonLabelH1(_ scale: Bool) -> Label { + let label = Label.label() label.styleH1(scale) return label } - class func commonLabelH2(_ scale: Bool) -> MFLabel { - let label = MFLabel.label() + class func commonLabelH2(_ scale: Bool) -> Label { + let label = Label.label() label.styleH2(scale) return label } - class func commonLabelH3(_ scale: Bool) -> MFLabel { - let label = MFLabel.label() + class func commonLabelH3(_ scale: Bool) -> Label { + let label = Label.label() label.styleH3(scale) return label } - class func commonLabelH32(_ scale: Bool) -> MFLabel { - let label = MFLabel.label() + class func commonLabelH32(_ scale: Bool) -> Label { + let label = Label.label() label.styleH32(scale) return label } - class func commonLabelB1(_ scale: Bool) -> MFLabel { - let label = MFLabel.label() + class func commonLabelB1(_ scale: Bool) -> Label { + let label = Label.label() label.styleB1(scale) return label } - class func commonLabelB2(_ scale: Bool) -> MFLabel { - let label = MFLabel.label() + class func commonLabelB2(_ scale: Bool) -> Label { + let label = Label.label() label.styleB2(scale) return label } - class func commonLabelB3(_ scale: Bool) -> MFLabel { - let label = MFLabel.label() + class func commonLabelB3(_ scale: Bool) -> Label { + let label = Label.label() label.styleB3(scale) return label } - class func commonLabelB20(_ scale: Bool) -> MFLabel { - let label = MFLabel.label() + class func commonLabelB20(_ scale: Bool) -> Label { + let label = Label.label() label.styleB20(scale) return label } - class func label() -> MFLabel { + class func label() -> Label { return Label(frame: CGRect.zero) } - */ + //------------------------------------------------------ // MARK: - Functions From 1b1c35873a10dfec7340d65002bddafb9e62fe53 Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Thu, 11 Apr 2019 14:25:34 -0400 Subject: [PATCH 07/19] development of Label conversion. wip. --- MVMCoreUI/Atoms/Views/Label.swift | 42 ++++++++++++------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index b0b32fcc..ee6ec1ab 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -22,7 +22,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { // Set this to use a custom sizing object during updateView instead of the standard. var sizeObject: MFSizeObject? - private var scaleSize: NSNumber? + private var scaleSize: CGFloat? // Used for scaling the font in updateView. private var originalAttributedString: NSAttributedString? @@ -43,15 +43,9 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { var hasText: Bool { - if let text = text, !text.isEmpty { - return true - } + guard let text = text, let attributedText = attributedText else { return false } - if let attributedText = attributedText, !attributedText.string.isEmpty { - return true - } - - return false + return !text.isEmpty || !attributedText.string.isEmpty } //------------------------------------------------------ @@ -60,9 +54,9 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { func setupView() { - backgroundColor = UIColor.clear + backgroundColor = .clear numberOfLines = 0 - lineBreakMode = NSLineBreakMode.byWordWrapping + lineBreakMode = .byWordWrapping translatesAutoresizingMaskIntoConstraints = false } @@ -142,7 +136,6 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { return Label(frame: CGRect.zero) } - //------------------------------------------------------ // MARK: - Functions //------------------------------------------------------ @@ -281,43 +274,40 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { func updateView(_ size: CGFloat) { - scaleSize = NSNumber(value: Float(size)) + scaleSize = size if let originalAttributedString = originalAttributedString { let attributedString = NSMutableAttributedString(attributedString: originalAttributedString) attributedString.removeAttribute(.font, range: NSRange(location: 0, length: attributedString.length)) originalAttributedString.enumerateAttribute(.font, in: NSRange(location: 0, length: originalAttributedString.length), options: [], using: { value, range, stop in + // Loop the original attributed string, resize the fonts. - let font: UIFont? = (value as? UIFont)?.withSize((MFStyler.sizeObjectGeneric(forCurrentDevice: ((value as? UIFont)?.pointSize)!)?.getValueBased(onSize: size))!) - attributedString.addAttribute(.font, value: font as Any, range: range) + if let fontObj = value as? UIFont, let stylerSize = MFStyler.sizeObjectGeneric(forCurrentDevice: fontObj.pointSize)?.getValueBased(onSize: size) { + + attributedString.addAttribute(.font, value: fontObj.withSize(stylerSize) as Any, range: range) + } }) attributedText = attributedString } else if !MVMCoreGetterUtility.fequal(a: Float(standardFontSize), b: 0.0) { - var sizeObject: MFSizeObject? = self.sizeObject - - if sizeObject == nil { - sizeObject = MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) + if let sizeObject: MFSizeObject = self.sizeObject ?? MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) { + self.font = self.font.withSize(sizeObject.getValueBased(onSize: size)) } - - self.font = self.font.withSize(sizeObject?.getValueBased(onSize: size) ?? 0.0) } } func setFont(_ font: UIFont, scale: Bool) { + self.font = font setScale(scale) } func setScale(_ scale: Bool) { + if scale { standardFontSize = font.pointSize - if let scaleSize = scaleSize { - updateView(CGFloat(scaleSize.floatValue)) - } else { - updateView(MVMCoreUISplitViewController.getApplicationViewWidth()) - } + updateView(scaleSize ?? MVMCoreUISplitViewController.getApplicationViewWidth()) } else { standardFontSize = 0 } From d6fdf9958e8665688e4b1b44af11521a91b673a5 Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Fri, 12 Apr 2019 12:12:33 -0400 Subject: [PATCH 08/19] Converted MFLabel to Label. --- MVMCoreUI/Atoms/Views/Label.swift | 93 ++++++++++++++----------------- 1 file changed, 41 insertions(+), 52 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index ee6ec1ab..fb9fee06 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -33,7 +33,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } set(accessibilityTraits) { if accessibilityTraits.rawValue & UIAccessibilityTraits.header.rawValue != 0 { - let noHeaderTraits: UIAccessibilityTraits = UIAccessibilityTraits(rawValue: accessibilityTraits.rawValue - UIAccessibilityTraits.header.rawValue) + let noHeaderTraits = UIAccessibilityTraits(rawValue: accessibilityTraits.rawValue - UIAccessibilityTraits.header.rawValue) super.accessibilityTraits = noHeaderTraits } else { super.accessibilityTraits = accessibilityTraits @@ -42,9 +42,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } var hasText: Bool { - guard let text = text, let attributedText = attributedText else { return false } - return !text.isEmpty || !attributedText.string.isEmpty } @@ -53,7 +51,6 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { //------------------------------------------------------ func setupView() { - backgroundColor = .clear numberOfLines = 0 lineBreakMode = .byWordWrapping @@ -84,55 +81,55 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { // MARK: - Functions //------------------------------------------------------ - class func commonLabelH1(_ scale: Bool) -> Label { + static func commonLabelH1(_ scale: Bool) -> Label { let label = Label.label() label.styleH1(scale) return label } - class func commonLabelH2(_ scale: Bool) -> Label { + static func commonLabelH2(_ scale: Bool) -> Label { let label = Label.label() label.styleH2(scale) return label } - class func commonLabelH3(_ scale: Bool) -> Label { + static func commonLabelH3(_ scale: Bool) -> Label { let label = Label.label() label.styleH3(scale) return label } - class func commonLabelH32(_ scale: Bool) -> Label { + static func commonLabelH32(_ scale: Bool) -> Label { let label = Label.label() label.styleH32(scale) return label } - class func commonLabelB1(_ scale: Bool) -> Label { + static func commonLabelB1(_ scale: Bool) -> Label { let label = Label.label() label.styleB1(scale) return label } - class func commonLabelB2(_ scale: Bool) -> Label { + static func commonLabelB2(_ scale: Bool) -> Label { let label = Label.label() label.styleB2(scale) return label } - class func commonLabelB3(_ scale: Bool) -> Label { + static func commonLabelB3(_ scale: Bool) -> Label { let label = Label.label() label.styleB3(scale) return label } - class func commonLabelB20(_ scale: Bool) -> Label { + static func commonLabelB20(_ scale: Bool) -> Label { let label = Label.label() label.styleB20(scale) return label } - class func label() -> Label { + static func label() -> Label { return Label(frame: CGRect.zero) } @@ -141,21 +138,16 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { //------------------------------------------------------ static func setLabel(_ label: UILabel?, withHTML html: String?) { + let data: Data? = html?.data(using: .utf8) - if data != nil { - let error: Error? = nil - if let data = data { - label?.attributedText = try? NSAttributedString(data: data, - options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue], - documentAttributes: nil) - - // compare with above... - // label?.attributedText = try? NSAttributedString(data: data, options: [ - // NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.html.rawValue - // ], documentAttributes: nil) - } - if let labelError = error { - try? MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: labelError, location: "LabelHTMLParse")!) + + if let data = data { + do { + label?.attributedText = try NSAttributedString(data: data, + options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue], + documentAttributes: nil) + } catch { + MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: error, location: "LabelHTMLParse")!) } } } @@ -178,24 +170,24 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { label.accessibilityLabel = accessibilityText } - let fontSize = json?.floatForKey("fontSize") + let fontSize = json?.floatForKey("fontSize") ?? 0.0 - if let fontName = json?.optionalStringForKey("fontName"), let fontSize = fontSize { - label.font = MFFonts.mfFont(withName: fontName, size: CGFloat(fontSize) == 0.0 ? label.font.pointSize : CGFloat(fontSize)) - } else if let fontSize = fontSize { + if let fontName = json?.optionalStringForKey("fontName") { + label.font = MFFonts.mfFont(withName: fontName, size: fontSize == 0.0 ? label.font.pointSize : CGFloat(fontSize)) + } else { label.font = label.font.withSize(CGFloat(fontSize)) } if let attributes = json?.arrayForKey("attributes"), let labelText = label.text { - let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font, - NSAttributedString.Key.foregroundColor: label.textColor]) + let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font as Any, + NSAttributedString.Key.foregroundColor: label.textColor as Any]) for case let attribute as [String: Any] in attributes { - let location = attribute.floatForKey("location") - let length = attribute.floatForKey("length") + let range = NSRange(location: Int(attribute.floatForKey("location")), + length: Int(attribute.floatForKey("length"))) - let range = NSRange(location: Int(location), length: Int(length)) + guard let attributeType = attribute.optionalStringForKey(KeyType) else { continue } - switch attribute.stringForkey(KeyType){ + switch attributeType { case "underline": attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range) @@ -208,7 +200,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } case "font": let fontSize = attribute.floatForKey("size") - var font: UIFont? + let font: UIFont? if let fontName = attribute.optionalStringForKey("name"), !fontName.isEmpty { font = MFFonts.mfFont(withName: fontName, size: fontSize != 0.0 ? CGFloat(fontSize) : CGFloat(label.font.pointSize)) @@ -216,9 +208,8 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { font = label.font.withSize(CGFloat(fontSize)) } - if font != nil { - attributedString.addAttribute(.font, value: font as Any, range: range) - } + attributedString.addAttribute(.font, value: font as Any, range: range) + default: continue } @@ -273,38 +264,30 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { } func updateView(_ size: CGFloat) { - scaleSize = size if let originalAttributedString = originalAttributedString { let attributedString = NSMutableAttributedString(attributedString: originalAttributedString) attributedString.removeAttribute(.font, range: NSRange(location: 0, length: attributedString.length)) - originalAttributedString.enumerateAttribute(.font, in: NSRange(location: 0, length: originalAttributedString.length), options: [], using: { value, range, stop in - // Loop the original attributed string, resize the fonts. if let fontObj = value as? UIFont, let stylerSize = MFStyler.sizeObjectGeneric(forCurrentDevice: fontObj.pointSize)?.getValueBased(onSize: size) { - attributedString.addAttribute(.font, value: fontObj.withSize(stylerSize) as Any, range: range) } }) attributedText = attributedString - } else if !MVMCoreGetterUtility.fequal(a: Float(standardFontSize), b: 0.0) { - if let sizeObject: MFSizeObject = self.sizeObject ?? MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) { - self.font = self.font.withSize(sizeObject.getValueBased(onSize: size)) - } + } else if !MVMCoreGetterUtility.fequal(a: Float(standardFontSize), b: 0.0), let sizeObject: MFSizeObject = self.sizeObject ?? MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) { + self.font = self.font.withSize(sizeObject.getValueBased(onSize: size)) } } func setFont(_ font: UIFont, scale: Bool) { - self.font = font setScale(scale) } func setScale(_ scale: Bool) { - if scale { standardFontSize = font.pointSize updateView(scaleSize ?? MVMCoreUISplitViewController.getApplicationViewWidth()) @@ -318,11 +301,17 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { //------------------------------------------------------ func setAsMolecule() { - // Empty + + setupView() } func setWithJSON(_ json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { Label.setUILabel(self, withJSON: json, delegate: delegate, additionalData: additionalData) + originalAttributedString = attributedText + + if let actionText = dictionary["actionText"] as? String { + self.actionText = actionText + } } } From 71f1f499e07df833c28fbc951b1bb25b43745ffa Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Fri, 12 Apr 2019 12:23:55 -0400 Subject: [PATCH 09/19] optional check improvements. --- MVMCoreUI/Atoms/Views/Label.swift | 134 +++++++++++++++--------------- 1 file changed, 66 insertions(+), 68 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index fb9fee06..75f21ce3 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -139,83 +139,81 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { static func setLabel(_ label: UILabel?, withHTML html: String?) { - let data: Data? = html?.data(using: .utf8) + guard let data = html?.data(using: .utf8) else { return } - if let data = data { - do { - label?.attributedText = try NSAttributedString(data: data, - options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue], - documentAttributes: nil) - } catch { - MVMCoreUILoggingHandler.shared()?.addError(toLog: MVMCoreErrorObject.createErrorObject(for: error, location: "LabelHTMLParse")!) + do { + label?.attributedText = try NSAttributedString(data: data, + options: [NSAttributedString.DocumentReadingOptionKey.documentType:NSAttributedString.DocumentType.html, NSAttributedString.DocumentReadingOptionKey.characterEncoding: String.Encoding.utf8.rawValue], + documentAttributes: nil) + } catch { + if let coreErrorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "LabelHTMLParse") { + MVMCoreUILoggingHandler.shared()?.addError(toLog: coreErrorObject) } } } static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: NSObject?, additionalData: [AnyHashable: Any]?) { - if let label = label { - label.text = json?.optionalStringForKey(KeyText) - setLabel(label, withHTML: json?.stringForkey("html")) - - if let textColorHex = json?.optionalStringForKey(KeyTextColor) { - label.textColor = UIColor.mfGet(forHex: textColorHex) - } - - if let backgroundColorHex = json?.optionalStringForKey(KeyBackgroundColor) { - label.backgroundColor = UIColor.mfGet(forHex: backgroundColorHex) - } - - if let accessibilityText = json?.optionalStringForKey("accessibilityText") { - label.accessibilityLabel = accessibilityText - } - - let fontSize = json?.floatForKey("fontSize") ?? 0.0 - - if let fontName = json?.optionalStringForKey("fontName") { - label.font = MFFonts.mfFont(withName: fontName, size: fontSize == 0.0 ? label.font.pointSize : CGFloat(fontSize)) - } else { - label.font = label.font.withSize(CGFloat(fontSize)) - } - - if let attributes = json?.arrayForKey("attributes"), let labelText = label.text { - let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font as Any, - NSAttributedString.Key.foregroundColor: label.textColor as Any]) - for case let attribute as [String: Any] in attributes { - let range = NSRange(location: Int(attribute.floatForKey("location")), - length: Int(attribute.floatForKey("length"))) + guard let label = label else { return } + + label.text = json?.optionalStringForKey(KeyText) + setLabel(label, withHTML: json?.stringForkey("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?.floatForKey("fontSize") ?? 0.0 + + if let fontName = json?.optionalStringForKey("fontName") { + label.font = MFFonts.mfFont(withName: fontName, size: fontSize == 0.0 ? label.font.pointSize : CGFloat(fontSize)) + } else { + label.font = label.font.withSize(CGFloat(fontSize)) + } + + if let attributes = json?.arrayForKey("attributes"), let labelText = label.text { + let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: label.font as Any, + NSAttributedString.Key.foregroundColor: label.textColor as Any]) + for case let attribute as [String: Any] in attributes { + let range = NSRange(location: Int(attribute.floatForKey("location")), + length: Int(attribute.floatForKey("length"))) + + guard let attributeType = attribute.optionalStringForKey(KeyType) else { continue } + + switch attributeType { + case "underline": + attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range) - guard let attributeType = attribute.optionalStringForKey(KeyType) else { continue } + case "strikethrough": + attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick, range: range) - switch attributeType { - case "underline": - attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single, range: range) - - case "strikethrough": - attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick, range: range) - - case "color": - if let colorHex = attribute.optionalStringForKey(KeyTextColor), !colorHex.isEmpty { - attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range) - } - case "font": - let fontSize = attribute.floatForKey("size") - let font: UIFont? - - if let fontName = attribute.optionalStringForKey("name"), !fontName.isEmpty { - font = MFFonts.mfFont(withName: fontName, size: fontSize != 0.0 ? CGFloat(fontSize) : CGFloat(label.font.pointSize)) - } else { - font = label.font.withSize(CGFloat(fontSize)) - } - - attributedString.addAttribute(.font, value: font as Any, range: range) - - default: - continue + case "color": + if let colorHex = attribute.optionalStringForKey(KeyTextColor), !colorHex.isEmpty { + attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range) } + case "font": + let fontSize = attribute.floatForKey("size") + let font: UIFont? + + if let fontName = attribute.optionalStringForKey("name"), !fontName.isEmpty { + font = MFFonts.mfFont(withName: fontName, size: fontSize != 0.0 ? CGFloat(fontSize) : CGFloat(label.font.pointSize)) + } else { + font = label.font.withSize(CGFloat(fontSize)) + } + + attributedString.addAttribute(.font, value: font as Any, range: range) + + default: + continue } - label.attributedText = attributedString } + label.attributedText = attributedString } } @@ -310,8 +308,8 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol { originalAttributedString = attributedText - if let actionText = dictionary["actionText"] as? String { - self.actionText = actionText - } +// if let actionText = dictionary["actionText"] as? String { +// self.actionText = actionText +// } } } From da1f5a5703d935fb3660f4055c5234c676ce99a2 Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Mon, 15 Apr 2019 16:50:35 -0400 Subject: [PATCH 10/19] Converted MFLabel (objc) to Label (Swift). Pulled LabelWithoutAccessibilityTraits from Mobilefirst module and converted it. Altered imports where needed. --- MVMCoreUI.xcodeproj/project.pbxproj | 14 +- MVMCoreUI/Atoms/TextFields/MFTextField.h | 4 +- MVMCoreUI/Atoms/TextFields/MFTextField.m | 2 - MVMCoreUI/Atoms/TextFields/MFTextField.xib | 6 +- MVMCoreUI/Atoms/Views/Label.swift | 103 ++++--- MVMCoreUI/Atoms/Views/LabelView.h | 4 +- MVMCoreUI/Atoms/Views/LabelView.m | 3 +- .../Atoms/Views/LabelWithInternalButton.swift | 4 +- .../LabelWithoutAccessibilityTraits.swift | 35 +++ MVMCoreUI/Atoms/Views/MFLabel.h | 63 ---- MVMCoreUI/Atoms/Views/MFLabel.m | 291 ------------------ MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.h | 4 +- MVMCoreUI/Atoms/Views/MVMCoreUICheckBox.m | 3 +- .../TopLabelsAndBottomButtonsViewController.h | 1 - MVMCoreUI/MVMCoreUI.h | 2 - MVMCoreUI/Molecules/StandardHeaderView.swift | 8 +- MVMCoreUI/Molecules/TopLabelsView.h | 7 +- MVMCoreUI/Molecules/TopLabelsView.m | 5 +- .../MVMCoreUIMoleculeMappingObject.m | 2 +- 19 files changed, 125 insertions(+), 436 deletions(-) create mode 100644 MVMCoreUI/Atoms/Views/LabelWithoutAccessibilityTraits.swift delete mode 100644 MVMCoreUI/Atoms/Views/MFLabel.h delete mode 100644 MVMCoreUI/Atoms/Views/MFLabel.m diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index ff46aef9..015803e6 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -96,8 +96,6 @@ D29DF28021E7AA51003B2FB9 /* MVMCoreUIDetailViewProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF27F21E7AA50003B2FB9 /* MVMCoreUIDetailViewProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF28121E7AB23003B2FB9 /* MVMCoreUICommonViewsUtility.m */; }; D29DF28421E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF28221E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D29DF28921E7AC2B003B2FB9 /* MFLabel.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF28521E7AC2B003B2FB9 /* MFLabel.h */; settings = {ATTRIBUTES = (Public, ); }; }; - D29DF28A21E7AC2B003B2FB9 /* MFLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF28621E7AC2B003B2FB9 /* MFLabel.m */; }; D29DF28B21E7AC2B003B2FB9 /* ViewConstrainingView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29DF28721E7AC2B003B2FB9 /* ViewConstrainingView.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29DF28C21E7AC2B003B2FB9 /* ViewConstrainingView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF28821E7AC2B003B2FB9 /* ViewConstrainingView.m */; }; D29DF29521E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D29DF28D21E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m */; }; @@ -161,6 +159,7 @@ DBC4391922442197001AB423 /* DashLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391722442197001AB423 /* DashLine.swift */; }; DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391A224421A0001AB423 /* CaretButton.swift */; }; DBC4392122491730001AB423 /* LabelWithInternalButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBC4391C2245232D001AB423 /* LabelWithInternalButton.swift */; }; + DBE3596E22651FCB00AB87F5 /* LabelWithoutAccessibilityTraits.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBE3596D22651FCB00AB87F5 /* LabelWithoutAccessibilityTraits.swift */; }; DBEFFA04225A829700230692 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB891E822253FA8500022516 /* Label.swift */; }; /* End PBXBuildFile section */ @@ -263,8 +262,6 @@ D29DF27F21E7AA50003B2FB9 /* MVMCoreUIDetailViewProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIDetailViewProtocol.h; sourceTree = ""; }; D29DF28121E7AB23003B2FB9 /* MVMCoreUICommonViewsUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUICommonViewsUtility.m; sourceTree = ""; }; D29DF28221E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreUICommonViewsUtility.h; sourceTree = ""; }; - D29DF28521E7AC2B003B2FB9 /* MFLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFLabel.h; sourceTree = ""; }; - D29DF28621E7AC2B003B2FB9 /* MFLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFLabel.m; sourceTree = ""; }; D29DF28721E7AC2B003B2FB9 /* ViewConstrainingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewConstrainingView.h; sourceTree = ""; }; D29DF28821E7AC2B003B2FB9 /* ViewConstrainingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewConstrainingView.m; sourceTree = ""; }; D29DF28D21E7ADB8003B2FB9 /* ProgrammaticScrollViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProgrammaticScrollViewController.m; sourceTree = ""; }; @@ -318,13 +315,12 @@ D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreeLayerViewController.swift; sourceTree = ""; }; D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIViewControllerMappingObject.h; sourceTree = ""; }; D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIViewControllerMappingObject.m; sourceTree = ""; }; - D2C5001B21F8EE66001DA659 /* LabelWithInternalButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LabelWithInternalButton.h; sourceTree = ""; }; - D2C5001C21F8EE66001DA659 /* LabelWithInternalButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LabelWithInternalButton.m; sourceTree = ""; }; DB891E822253FA8500022516 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; DBC4391622442196001AB423 /* CaretView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretView.swift; sourceTree = ""; }; DBC4391722442197001AB423 /* DashLine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DashLine.swift; sourceTree = ""; }; DBC4391A224421A0001AB423 /* CaretButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaretButton.swift; sourceTree = ""; }; DBC4391C2245232D001AB423 /* LabelWithInternalButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelWithInternalButton.swift; sourceTree = ""; }; + DBE3596D22651FCB00AB87F5 /* LabelWithoutAccessibilityTraits.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelWithoutAccessibilityTraits.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -566,8 +562,6 @@ DBC4391722442197001AB423 /* DashLine.swift */, D29DF17E21E69E2E003B2FB9 /* MFView.h */, D29DF17F21E69E2E003B2FB9 /* MFView.m */, - D29DF28521E7AC2B003B2FB9 /* MFLabel.h */, - D29DF28621E7AC2B003B2FB9 /* MFLabel.m */, D29DF31E21ED0CBA003B2FB9 /* LabelView.h */, D29DF31F21ED0CBA003B2FB9 /* LabelView.m */, D29DF28721E7AC2B003B2FB9 /* ViewConstrainingView.h */, @@ -595,6 +589,7 @@ DB891E822253FA8500022516 /* Label.swift */, 0198F7A02256A80A0066C936 /* MFRadioButton.h */, 0198F7A22256A80A0066C936 /* MFRadioButton.m */, + DBE3596D22651FCB00AB87F5 /* LabelWithoutAccessibilityTraits.swift */, ); path = Views; sourceTree = ""; @@ -747,7 +742,6 @@ D29DF27521E79E81003B2FB9 /* MVMCoreUILoggingHandler.h in Headers */, D29DF28B21E7AC2B003B2FB9 /* ViewConstrainingView.h in Headers */, D29DF2B321E7B76D003B2FB9 /* MFLoadingSpinner.h in Headers */, - D29DF28921E7AC2B003B2FB9 /* MFLabel.h in Headers */, D29DF32521ED0DA2003B2FB9 /* TextButtonView.h in Headers */, D29DF25021E6A177003B2FB9 /* MFDigitTextBox.h in Headers */, D29DF2C621E7BF57003B2FB9 /* MFTabBarInteractor.h in Headers */, @@ -906,7 +900,6 @@ D274CA332236A78900B01B62 /* StandardFooterView.swift in Sources */, D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */, D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */, - D29DF28A21E7AC2B003B2FB9 /* MFLabel.m in Sources */, D206997821FB8A0B00CAE0DE /* MVMCoreUINavigationController.m in Sources */, D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */, 01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */, @@ -919,6 +912,7 @@ D29DF28C21E7AC2B003B2FB9 /* ViewConstrainingView.m in Sources */, D29DF17B21E69E1F003B2FB9 /* PrimaryButton.m in Sources */, D29DF11D21E684A9003B2FB9 /* MVMCoreUISplitViewController.m in Sources */, + DBE3596E22651FCB00AB87F5 /* LabelWithoutAccessibilityTraits.swift in Sources */, 0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */, D29DF29821E7ADB8003B2FB9 /* MFScrollingViewController.m in Sources */, D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */, diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.h b/MVMCoreUI/Atoms/TextFields/MFTextField.h index 81b4059f..27dd8414 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.h +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.h @@ -11,7 +11,7 @@ @class PrimaryButton; @class MFTextField; -@class MFLabel; +@class Label; @protocol MFTextFieldDelegate @@ -34,7 +34,7 @@ @property (nullable, weak, nonatomic) IBOutlet UIView *textFieldContainerView; @property (nullable, weak, nonatomic) IBOutlet UITextField *textField; -@property (nullable, weak, nonatomic) IBOutlet MFLabel *formLabel; +@property (nullable, weak, nonatomic) IBOutlet Label *formLabel; @property (nullable, weak, nonatomic) IBOutlet UIView *separatorView;//make it public so outsider class can know the posistion of it. @property (nullable, weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint; diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.m b/MVMCoreUI/Atoms/TextFields/MFTextField.m index 565e086c..64169579 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.m +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.m @@ -7,12 +7,10 @@ // #import "MFTextField.h" -#import #import "MFTextFieldSubclassExtension.h" #import "MFStyler.h" #import "UIColor+MFConvenience.h" #import "MVMCoreUICommonViewsUtility.h" -#import "MFLabel.h" #import "MVMCoreUIUtility.h" #import "MVMCoreUIConstants.h" #import diff --git a/MVMCoreUI/Atoms/TextFields/MFTextField.xib b/MVMCoreUI/Atoms/TextFields/MFTextField.xib index b60f1ff3..e839533f 100644 --- a/MVMCoreUI/Atoms/TextFields/MFTextField.xib +++ b/MVMCoreUI/Atoms/TextFields/MFTextField.xib @@ -1,11 +1,11 @@ - + - + @@ -98,7 +98,7 @@ -