Ios 更改html中的默认字体颜色创建NSAttribute字符串

Ios 更改html中的默认字体颜色创建NSAttribute字符串,ios,nsattributedstring,Ios,Nsattributedstring,“123”和“789”默认颜色为黑色,但我想换成另一种颜色,我该怎么办 TTTAttributedLabel * cmdTextView = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(200, 100, 100, 30)]; cmdTextView.backgroundColor = [UIColor lightGrayColor]; cmdTextView.textColor = [UIColor redColor]; [self.

“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];
TTTAttributedLabel*cmdTextView=[[TTTAttributedLabel alloc]initWithFrame:CGRectMake(200100100,30)];
cmdTextView.backgroundColor=[UIColor lightGrayColor];
cmdTextView.textColor=[UIColor redColor];
[self.view addSubview:cmdTextView];
NSString*s=@“123456789”;
NSMutableAttributedString*属性=[[NSMutableAttributedString alloc]initWithData:[s dataUsingEncoding:NSNicoDestringEncoding]选项:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType}DocumentAttribute:nil错误:nil];
[cmdTextView setText:属性];

我找到了一个解决方案。希望能帮助你

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

枚举属性,并根据需要设置所需颜色。