I have a NSString with this format:
<p>When: Every day except Monday at 11:45am
</p><p>Where: Main Pool</p><p><br></p><p>Get refreshed in the main pool during the warm sunny days whilst participating in our animation's fit activities. Enjoy our aqua fitness 6 times per week.<br></p>
I use this code to display the html attributes and also set a default font size and color:
NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithData:[self.Description dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
__block BOOL found = NO;
[attrStr beginEditing];
[attrStr enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, attrStr.length) options:0 usingBlock:^(id value, NSRange range, BOOL *stop) {
if (value) {
UIFont *oldFont = (UIFont *)value;
UIFont *newFont = [oldFont fontWithSize:16];
[attrStr addAttribute:NSFontAttributeName value:newFont range:range];
[attrStr addAttribute:NSForegroundColorAttributeName
value:[UIColor darkGrayColor]
range:range];
found = YES;
}
}];
[attrStr endEditing];
cell.descLbl.attributedText = attrStr;
Those words doesn't show up:
fitness 6 times per week.<br></p>
it only shows some weird dots-lines at the top of where the letters should be.
I believe the problem is when I change the String to unicode, the length of the String changes and so the range. How can I fix this?