我需要在我的 Metal 应用程序中呈现一些文本。与其手动进行,我更愿意使用 Apple 的文本渲染 API。
在一个简单的空窗口中调用此代码将drawRect打印字符串:
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"Helvetica" size:26], NSFontAttributeName,[NSColor blackColor], NSForegroundColorAttributeName, nil];
NSAttributedString * s = [[NSAttributedString alloc] initWithString:@"Hello!"
attributes: attributes];
[s drawAtPoint:NSMakePoint(300, 300)];
但这在具有金属视图的窗口中不起作用。我想一切都会被冲洗掉?
是否可以?在 Metal 视图上显示按钮 (NSButton) 也是如此。
谢谢。