我無法在自定義CALayer中繪製字符串。 drawInContext方法被調用,但屏幕上沒有任何東西可見。我可以用純色填充圖層,但似乎無法在其上繪製字符串。如何在OSX中的CALayer上繪製字符串?
有什麼建議嗎?謝謝。
- (void)drawInContext:(CGContextRef)ctx
{
CGContextSaveGState(ctx);
NSString *myString = @"Hello World";
NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys:
[NSFont systemFontOfSize:14], NSFontAttributeName, nil];
[myString drawAtPoint:NSMakePoint(0,0) withAttributes:attr];
CGContextRestoreGState(ctx);
}
我有我需要繪製各種屬性的文本。我寧願自己繪製文本,因爲它比爲我的所有字符串創建CATextLayer並將其放入父圖層更通用。 – David 2011-03-15 02:32:43