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];
枚舉屬性,並設置想要的顏色時,情況。 – Larme