[英]change default font color in html create NSAttributedString
“ 123”和“ 789”的默認顏色是黑色,但是我想更改為另一種顏色,我該怎么做?
TTTAttributedLabel * cmdTextView = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(200, 100, 100, 30)];
cmdTextView.backgroundColor = [UIColor lightGrayColor];
cmdTextView.textColor = [UIColor redColor];
[self.view addSubview:cmdTextView];
NSString *s = @"123<font color='#FFFFFF'>456</font>789" ;
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc]initWithData:[s dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
[cmdTextView setText:attribute];
我找到了解決方案。 希望可以幫到你
NSString *s1 = [NSString stringWithFormat:"<span style=\"color:Your color\">%@</span>", s];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.