如何将 NSString 写入 NSView?

How to write NSString to the NSView?

我可以使用类似的东西(UI 而不是 NS)写信给 iOS。但失败 OSX?

NSString *sText = @"Hello";
[sText drawInRect:CGRectMake(x, y, 150, 20) withFont:[NSFont boldSystemFontOfSize:fSize]]; 
// No visible @interface for 'NSString' declares the selector 'drawInRect:withFont:'

您需要在 OS X:

上使用 NSAttributedString 属性
NSString *sText = @"Hello";
[sText drawInRect:CGRectMake(x, y, 150, 20) withAttributes: @{ NSFontAttributeName : 
                                             [NSFont boldSystemFontOfSize:fSize] }];

https://developer.apple.com/library/prerelease/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSString_AppKitAdditions/index.html

另一种方法:使用"drawAtPoint":

http://forums.macrumors.com/threads/drawing-text-to-an-nsview.904433/