【问题标题】:change default font color in html create NSAttributedString更改html中的默认字体颜色创建NSAttributedString
【发布时间】:2016-09-21 12:22:00
【问题描述】:

“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];

【问题讨论】:

  • 枚举属性,设置需要的颜色。

标签: ios nsattributedstring


【解决方案1】:

我找到了解决办法。希望能帮到你

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-12
    相关资源
    最近更新 更多