Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithData: [htmlString dataUsingEncoding: NSUnicodeStringEncoding]
- options: @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType }
- documentAttributes: nil
- error: nil];
- //Replace ALL fonts, without taking in account the different sizes, bold/italic => All the same
- [attributedString addAttribute: NSFontAttributeName
- value: [NSFont fontWithName: @"NotoSansCJKjp-Regular" size:14.0]
- range: NSMakeRange(0, [attributedString length])];
- [attributedString enumerateAttribute:NSForegroundColorAttributeName
- inRange:NSMakeRange(0, [attributedString length])
- options: kNilOptions
- usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
- if ([value isKindOfClass:[UIColor class]]) { //There is a color, we can check also its value if needed, like replace only blue, etc.
- UIColor *newColor = [UIColor colorFromHexString: @"454545"];
- [attributedString addAttribute:NSForegroundColorAttributeName value:newColor range:range];
- }
- }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement