CGContextShowTextAtPoint已经被弃用 - 现在我应该使用什么?

18

iOS 7 中以下内容将被视为过时: CGContextSelectFont, CGContextShowTextAtPoint. 那么我应该使用什么替代方法呢?


2
所有iOS beta API的更改都受NDA保护,不能在此讨论。这是适用于苹果开发者论坛的内容。 - Keith Smiley
2个回答

9
你可以使用[yourString drawAtPoint:aPoint withAttributes:dictOfAttributes];方法。相关文档请参考这里。或者你也可以在视图层次结构中添加一个UILabel

6

//开始绘图上下文 UIGraphicsBeginImageContext(imageSize);

//get the context for coreGraphics
CGContextRef ctx = UIGraphicsGetCurrentContext();

CGContextSetTextDrawingMode(ctx, kCGTextFill);
[[UIColor blackColor] setFill];
[@"yourstring" drawAtPoint:CGPointMake(0, 0) withAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica"  size:17]}];
//make image out of bitmap context
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接