简体   繁体   English

在html中更改默认字体颜色创建NSAttributedString

[英]change default font color in html create NSAttributedString

"123" and "789" default color is black but I want to change to another color,how can i do for this ? “ 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];

I find a solution. 我找到了解决方案。 Hope can help u 希望可以帮到你

NSString *s1 = [NSString stringWithFormat:"<span style=\"color:Your color\">%@</span>", s];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM