From ae4512abff1bd2bedeba5747d70836f66c320436 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Wed, 27 Mar 2019 10:13:51 -0400 Subject: [PATCH] html string --- MVMCoreUI/Atoms/Views/MFLabel.h | 2 ++ MVMCoreUI/Atoms/Views/MFLabel.m | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/MFLabel.h b/MVMCoreUI/Atoms/Views/MFLabel.h index 8d1d284f..193fe4fe 100644 --- a/MVMCoreUI/Atoms/Views/MFLabel.h +++ b/MVMCoreUI/Atoms/Views/MFLabel.h @@ -56,6 +56,8 @@ + (nonnull MFLabel *)commonLabelTopAlert:(BOOL)scale; // Setters ++ (void)setLabel:(nullable UILabel *)label withHTML:(nullable NSString *)html; ++ (void)setUILabel:(nullable UILabel *)label withJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData; - (void)styleB2:(BOOL)scale; - (void)styleBodyWithSize:(CGFloat)size scale:(BOOL)scale; - (void)styleBodyBold:(BOOL)scale; diff --git a/MVMCoreUI/Atoms/Views/MFLabel.m b/MVMCoreUI/Atoms/Views/MFLabel.m index e9b99860..eb9ed1c6 100644 --- a/MVMCoreUI/Atoms/Views/MFLabel.m +++ b/MVMCoreUI/Atoms/Views/MFLabel.m @@ -13,6 +13,7 @@ #import "UIColor+MFConvenience.h" #import "MFFonts.h" #import "MVMCoreUISplitViewController.h" +#import "MVMCoreUILoggingHandler.h" @import MVMCore.MVMCoreGetterUtility; @import MVMCore.NSDictionary_MFConvenience; @import MVMCore.MVMCoreJSONConstants; @@ -237,9 +238,21 @@ #pragma mark - Setters ++ (void)setLabel:(nullable UILabel *)label withHTML:(nullable NSString *)html { + NSData *data = [html dataUsingEncoding:kCFStringEncodingUTF8]; + if (data) { + NSError *error = nil; + label.attributedText = [[NSAttributedString alloc] initWithData:data options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:&error]; + if (error) { + [[MVMCoreUILoggingHandler sharedLoggingHandler] addErrorToLog:[MVMCoreErrorObject createErrorObjectForNSError:error location:@"LabelHTMLParse"]]; + } + } +} + + (void)setUILabel:(nullable UILabel *)label withJSON:(nullable NSDictionary *)json delegate:(nullable NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData { if (label) { label.text = [json string:KeyText]; + [self setLabel:label withHTML:[json string:@"html"]]; NSString *textColor = [json string:KeyTextColor]; if (textColor) { label.textColor = [UIColor mfGetColorForHex:textColor];