- (void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
CGContextSetFillColorWithColor(ctx, [[UIColor darkTextColor] CGColor]);
UIGraphicsPushContext(ctx);
[word drawAtPoint:CGPointMake(30.0f, 30.0f)
forWidth:200.0f
withFont:[UIFont boldSystemFontOfSize:32]
lineBreakMode:UILineBreakModeClip];
UIGraphicsPopContext();
}
Iphone Quartz 2D 提供了CGContextShowText来将文字画在CALayer上,但画出的中文是乱码,我查了很多资料,终于让我找到上面这种方法,调用 UIGraphicsPushContext是关键,否则是画不出来的,通过NSString 的 drawAtPoint 或者 drawPoint绘制,但是有点小问题还没有解决,若生成的文字不是水平的,就没有办法实现,估计要用Core Text来实现,希望对大家有帮助。