NSMutableAttributedString не может изменить цвет текста при вызове метода addAttribute

я хочу изменить цвет текста на основе третьей части библиотеки, которая называется "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;
}];

person Qijin    schedule 11.10.2014    source источник


Ответы (1)


Попробуйте использовать:

[mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName
                                    value:colorWithIntegerValue(195, 195, 195) range:priceStringRange];
person Michael Gaylord    schedule 29.10.2014