iPhone中的NSForegroundColorAttributeName键

YPK*_*YPK 4 iphone nsattributedstring uicolor

我听说在iPhone中添加了NSAttributedString但是当我使用键NSForegroundColorAttributeName来设置颜色时,我得到一个错误,说"NSForegroundColorAttributeName undeclared".我错过了什么吗?请帮我.

问候

Yallappa

rib*_*eto 11

我遇到了同样的问题,因为BarretJ提到你使用了kCTForegroundColorAttributeName常量.这是一个例子:

NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:countStr attributes:nil];

[attrStr addAttribute:(NSString*)kCTForegroundColorAttributeName 
                value:(id)[[UIColor greenColor] CGColor]
                range:range];
Run Code Online (Sandbox Code Playgroud)


Bar*_*ttJ 9

请尝试使用kCTForegroundColorAttributeName.