【问题标题】:NSMutableAttributedString can not change the text color when calling addAttribute methodNSMutableAttributedString 在调用 addAttribute 方法时不能改变文本颜色
【发布时间】:2014-10-11 02:59:21
【问题描述】:

我想根据第三部分库“TTTAttributedLabel”更改文本颜色,但这没有意义。这是我的代码:

 TTTAttributedLabel *priceInfoLabel.frame = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(self.view.width-12-realSize.width-priceSize.width, 15, realSize.width+priceSize.width, 18)];

priceInfoLabel.centerY = nameView.height/2;
priceInfoLabel.textColor = kRealPriceColor;
[priceInfoLabel setText:[NSString stringWithFormat:@"%@%@",realPriceText,priceText] afterInheritingLabelAttributesAndConfiguringWithBlock:^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
    NSRange priceStringRange = [[mutableAttributedString string] rangeOfString:priceText options:NSCaseInsensitiveSearch];
    [mutableAttributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:nil size:12] range:priceStringRange];
    [mutableAttributedString addAttribute:UITextAttributeTextColor
                                    value:colorWithIntegerValue(195, 195, 195) range:priceStringRange];
    return mutableAttributedString;
}];

【问题讨论】:

    标签: nsmutableattributedstring tttattributedlabel


    【解决方案1】:

    尝试使用:

    [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName
                                        value:colorWithIntegerValue(195, 195, 195) range:priceStringRange];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-15
      • 2021-12-23
      • 1970-01-01
      相关资源
      最近更新 更多