feat:Text add htmlText

This commit is contained in:
pengfei.zhou
2020-04-14 11:44:22 +08:00
committed by osborn
parent e73ad1db2b
commit 9e0b3e067b
14 changed files with 437 additions and 1 deletions

View File

@@ -126,6 +126,12 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
self.strikethrough = prop;
[self reloadParagraphStyle];
}];
} else if ([name isEqualToString:@"htmlText"]) {
NSAttributedString *attStr = [[NSAttributedString alloc] initWithData:[prop dataUsingEncoding:NSUnicodeStringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}
documentAttributes:nil
error:nil];
view.attributedText = attStr;
} else {
[super blendView:view forPropName:name propValue:prop];
}
@@ -142,6 +148,9 @@ - (NSMutableParagraphStyle *)ensureParagraphStyle {
- (void)reloadParagraphStyle {
NSString *labelText = self.view.text ?: @"";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
if (self.view.attributedText) {
[attributedString setAttributedString:self.view.attributedText];
}
[attributedString addAttribute:NSParagraphStyleAttributeName value:self.paragraphStyle range:NSMakeRange(0, [labelText length])];
if (self.underline) {
[attributedString addAttribute:NSUnderlineStyleAttributeName value:self.underline range:NSMakeRange(0, [labelText length])];