Jas*_*rts 11 cocoa objective-c
我已经想出如何使用NSBezierPath类在我的自定义视图类的drawRect函数中绘制形状,但我似乎无法弄清楚如何绘制文本.下面的代码是我到目前为止绘制文本(位于drawRect函数中):
NSText *text = [NSText new];
[text setTextColor: [NSColor yellowColor]];
[text setText: @"Hello!"];
Run Code Online (Sandbox Code Playgroud)
我猜我可能需要提供一个NSRect或NSPoint来告诉NSText对象在哪里绘制自己,但我在Cocoa文档中找不到有关如何执行此操作的任何内容.
Ben*_*son 23
你可以尝试这些方面:
//note we are using the convenience method, so we don't need to autorelease the object
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"Helvetica" size:26], NSFontAttributeName,[NSColor blackColor], NSForegroundColorAttributeName, nil];
NSAttributedString * currentText=[[NSAttributedString alloc] initWithString:@"Cat" attributes: attributes];
NSSize attrSize = [currentText size];
[currentText drawAtPoint:NSMakePoint(yourX, yourY)];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12438 次 |
| 最近记录: |