Advertisement
Larme

Untitled

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