您的位置:首页 > 其它

Iphone Quartz 2D CALayer 绘制中文,问题解决

2011-12-28 15:08 246 查看
- (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来实现,希望对大家有帮助。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  quartz iphone layer