2015-12-08 83 views
1

「123」和「789」的默認顏色是黑色,但我想改變爲另一種顏色,我該如何做到這一點?更改html中的默認字體顏色創建NSAttributedString

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]; 
+0

枚舉屬性,並設置想要的顏色時,情況。 – Larme

回答

-1

我找到了解決辦法。希望可以幫助你ü

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