【发布时间】:2012-03-30 18:00:32
【问题描述】:
我正在尝试将具有特定字体和颜色的文本放入 NSTextView。我可以把文字放进去就好了,但它失去了我的属性:
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont fontWithName:@"Monaco" size:10], @"NSFontAttributeName",
[NSColor blueColor], @"NSForegroundColorAttributeName",
nil];
NSAttributedString *string = [[NSAttributedString alloc] initWithString:someNSString
attributes: dict];
[someNSTextStorage appendAttributedString:string];
我已经阅读了所有相关的类引用(NSTextView、NSTextStorage、NSAttributedString 等...),但我仍然不知道为什么它不能按预期工作。
我做错了什么/错过了什么?
【问题讨论】:
-
我仍然不确定问题出在哪里,但我可以通过在 appendAttributedString 之后使用
[storage setForegroundColor:[NSColor blueColor]];和[storage setFont:[NSFont fontWithName:@"Monaco" size:10]];来解决它:
标签: objective-c cocoa