当使用下面的代码片段时,我在
上得到了undefined/undeclared error
NSForegroundColorAttributeName
我的代码片段
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:self.myDisplayTxt];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
请告诉我
最佳答案
尝试使用 kCTForegroundColorAttributeName。
你的代码
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:self.myDisplayTxt];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
进行此更改
[string addAttribute:(NSString*)kCTForegroundColorAttributeName
value:(id)[[UIColor redColor] CGColor]
range:NSMakeRange(0,5)];
来自 apple 的示例代码,
在您使用 addAttribute:
#if (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
#import <CoreText/CoreText.h>
#else
#import <AppKit/AppKit.h>
#endif
请看看这是否有帮助。不要忘记添加核心文本框架
关于ios - NSForegroundColorAttributeName 未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10310223/